<?php

namespace app\macht\controller;

use app\common\command\Baobiao;
use app\common\command\Tstatis;
use app\common\controller\AfterPayPutCardTest;
use app\common\controller\Balance;
use app\common\controller\Balancet;
use app\common\controller\Bonus;
use app\common\controller\CardCustom;
use app\common\controller\CardMarke;
use app\common\controller\CardPut;
use app\common\controller\CardPuttest;
use app\common\controller\Helpinfo;
use app\common\controller\Level;
use app\common\controller\Leveltest;
use app\common\controller\Platurl;
use app\common\controller\TemplateMsg;
use app\common\controller\TemplateMsgt;
use app\common\controller\TestBase;
use app\common\controller\Ydhwork;
use app\common\model\CardBirthdayCare;
use app\common\model\CardBirthdayCareLog;
use app\common\model\CardBizPut;
use app\common\model\CardBizPutLogMember;
use app\common\model\CardBonusPut;
use app\common\model\CardBonusRule;
use app\common\model\CardConsume;
use app\common\model\CardCzLog;
use app\common\model\CardFreecard;
use app\common\model\CardGeneral;
use app\common\model\CardGive;
use app\common\model\CardGivecardLog;
use app\common\model\CardGivePutCard;
use app\common\model\CardMember;
use app\common\model\CardPaycard;
use app\common\model\CardPaycardlog;
use app\common\model\CardQrcode;
use app\common\model\CardRankUserLog;
use app\common\model\CardShareLog;
use app\common\model\CardShareRule;
use app\common\model\CardShareUser;
use app\common\model\CardTimingPutUser;
use app\common\model\CardUrlDict;
use app\common\model\CardUserBonus;
use app\common\model\CardUserFee;
use app\common\model\CardUserGet;
use app\common\model\CardRank;
use app\common\model\Agent;
use app\common\model\CardUserGetAli;
use app\common\model\CardUserLog;
use app\common\model\CardUserRecLog;
use app\common\model\CardUserUpdate;
use app\common\model\CardCzgive;
use app\common\model\LoginCode;
use app\common\model\LoginUsers;
use app\common\model\MchStatis;
use app\common\model\MerchantCate;
use app\common\model\Mstatis;
use app\common\model\OpenTemplate;
use app\common\model\Paylog;
use app\common\model\PaymentCardPut;
use app\common\model\PaymentCardPutLog;
use app\common\model\ProfitAccount;
use app\common\model\ProfitList;
use app\common\model\WxOpen;
use app\common\model\Momerchant;
use app\common\model\Merchant;
use app\common\model\System;
use app\common\controller\Carddate;
use app\common\controller\AdminBase;
use app\common\model\YdhOpen;
use app\index\controller\Adview;
use app\index\controller\Wxcard;
use app\mobile\controller\Cardacitvate;
use app\mobile\controller\Cardshop;
use think\Controller;
use think\Db;
use think\Debug;
use think\Queue;
use think\Request;
use think\config;
use think\Session;
use Wechat\Wxobjopen;
use Wnkj\WnCardObj;
use Wnkj\WnObj;

class Test extends MachBase
{


    public function getqrcode(){
        $mid = 1229;
        $res = $this->getmachcardbgimg($mid);
        var_dump($res);
    }

    //门店开卡一键二维码带背景
    public function getmachcardbgimg($mid){
        //保存路径
        $qr2 = $_SERVER['DOCUMENT_ROOT'] . "/bizcard/qrcode/" ."bg_". $mid . '.png';
        if (file_exists($qr2)) {
            $qr_return = "/bizcard/qrcode/" ."bg_". $mid . '.png';
            return $qr_return;
        }
        //获取商家信息
        $Momerchant = new Momerchant();
        $sql['id'] = Session::get('login_top_mid');
        $moinfo = $Momerchant->where($sql)->field('id,merchant_name,img')->find();
        $domains = request()->domain();
        $logo_url = str_replace($domains,$_SERVER['DOCUMENT_ROOT'],$moinfo['img']);
        $merchant_name = $moinfo['merchant_name'];
        //背景图
        $bg_img = $_SERVER['DOCUMENT_ROOT'].'/static/img/mach_card_bg.png';

        //打开LOGO
        $image = \think\Image::open($logo_url);
        //生成缩略图
        $mologo = $_SERVER['DOCUMENT_ROOT'] . "/momach/thumb/" ."bg_". $moinfo['id'] . '.png';
        $image->thumb(110, 110)->save($mologo);
        //打开背景图
        $img = \think\Image::open($bg_img);
        //合成图片  logo
        $img->water($mologo, array(470, 1490))->save($qr2);
        //打开图片
        $imgs = \think\Image::open($qr2);
        //合成图片  字
        $imgs->text($merchant_name, $_SERVER['DOCUMENT_ROOT'].'/static/font/vistaYahei.ttf',42,'#CCCCCC',\think\Image::WATER_SOUTHWEST,array(610, -160))->save($qr2);
//        exit();
        //获取二维码
        $CardQrcode = new CardQrcode();
        $map['mid'] = $mid;
        $map['type'] = 1;
        $info = $CardQrcode->where($map)->find();
        if ($info){
            //二维码
            $qr = $_SERVER['DOCUMENT_ROOT'] . "/bizcard/" . $info['id'] . '.png';
            //合成图片
            $imgs->water($qr, array(150, 710))->save($qr2);

            $qr_return = "/bizcard/qrcode/" ."bg_". $mid . '.png';
        }else{
            $qr_return = '';
        }
        return $qr_return;
    }

    public function ete(){
//        $option['rec_id'] = $CardUserRecLog->id;
//        $option['mid'] = 518;
//        $option['card_id'] = "pG-qPwzB3auZWvWENmj57oWZR3GE";
//        $option['poly'] = 'max';
//        $option['cs_id'] ='';
//        $option['code'] = '010232645631';
//        $option['orderid'] = '';
//        $option['num'] = '2';
//        $option['bd_cate'] = 'balance';
//        $option['type'] = 1;//变动 1增加 2减少
//        $option['cate'] = 1;  //变动类型
//        $option['pay_cate'] = 4; //支付方式
//        $option['source'] = '测试';  //来源
//        $option['kuantai'] = '测试';  //款台
//        $option['remark'] = '测试'; //备注
//        $option['action_user'] = '测试';//操作人
        $arr['card_id'] = "pG-qPwzB3auZWvWENmj57oWZR3GE";
        $arr['type'] = 'pay_balance';
        $arr['openid'] = 'oG-qPw6SRIlnpxfcF_BKqxUdIGxc';
        $arr['add_balance'] = 10;
        $arr['balance'] = 2;
        $TemplateMsg = new TemplateMsg();
        $res = $TemplateMsg->send_tpl('pay_balance', $arr);
        var_dump($res);
    }

    public function fitlist()
    {
        $mapmt['id'] = 49;
        $ProfitList = new ProfitList();
        $info = $ProfitList->where($mapmt)->find();
        if ($info['status'] == 'P') {
            $re_param['result_code'] = "SUCCESS";
            $re_param['result_msg'] = "请等待分账完成";
        } elseif ($info['status'] == 'Y') {
            $re_param['result_code'] = "ERROR";
            $re_param['result_msg'] = "请勿重复操作";
        } else {
            $datap['status'] = 'P';
            $ProfitList->save($datap, $mapmt);
            $this->task_biz_fenzhang($info);
            $re_param['result_code'] = "SUCCESS";
            $re_param['result_msg'] = "处理成功";
            var_dump(111);
        }
    }

    public function fittest(){
        $res = $this->profit_account(979,10);
        var_dump($res);
    }

    private function profit_account($mid,$price)
    {
        $ProfitAccount = new ProfitAccount();
        $map['mid'] = $mid;
        $map['status'] = "Y";
        $profitacc = $ProfitAccount->where($map)->select();
        $re=[];
        foreach ($profitacc as $k => $v) {
            if($v['fz_type']=="B"){
                $amount=number_format($v['fz_num']*$price,"2",".","")*100;
            }elseif($v['fz_type']=="G"){
                $amount=$v['fz_num']*100;
            }

            $re[$k]['type']=$v['type'];
            $re[$k]['account']=$v['account'];
            $re[$k]['amount']=$amount;
            $re[$k]['description']=date('Y-m-d')."日分账";
        }
        return $re;

    }


    //senduserlist   add_bonus remark
    public function sendmassbonus(Request $request){
        $param['senduserlist'] = '1855,4457';
        $param['add_bonus'] = 10;
        $param['remark'] = 'asdasd';
        $CardUserGet = new CardUserGet();
        $CardBonusPut = new CardBonusPut();
        $sdata['param']['card_id'] = $card_id = $this->get_cardus_id();;
        $sdata['param']['add_bonus'] = $param['add_bonus'];
        $sdata['param']['remark'] = $param['remark'];
        $sdata['param']['action_user'] = Session::get('user.nickname');
        $map['top_mid'] = Session::get('login_top_mid');
        $map['id'] = array('in', $param['senduserlist']);
        $total = $CardUserGet->where($map)->count();
        $ress = ['error'];
        for ($i = 0; $i < $total; $i = $i + 50) {
            $sdata['param']['userlist'] = $CardUserGet->where($map)->field('code,card_id')->limit($i, 50)->select();
            $ress[$i] = $this->task_bonus_put($sdata);
        }
        $data['res_info'] = json_encode($ress, JSON_UNESCAPED_UNICODE);
        $data['top_mid'] = Session::get('login_top_mid');
        $data['card_id'] = $card_id = $this->get_cardus_id();;
        $data['remark'] = $param['remark'];
        $data['add_bonus'] = $param['add_bonus'];
        $data['senduserlist'] = $param['senduserlist'];
        $data['create_time'] = time();
        $CardBonusPut->save($data);
        if ($ress[0]=='success'){
            $rarr['code'] = 0;
            $rarr['message'] = '成功';
        } else {
            $rarr['code'] = 9001;
            $rarr['message'] = '失败';
        }
        return json($rarr);

    }

    //批量执行跟随推荐(积分
    public function task_bonus_put($param)
    {
        //初始化微信类
        if (isset($param['param']['card_id'])) {
            $userlist = $param['param']['userlist'];                                    //用户列表
            foreach ($userlist as $k => $v) {
                $option['card_id'] = $param['param']['card_id'];                        //card_id
                $option['code'] = $v['code'];                                           //code
                $option['orderid'] = '';
                $option['num'] = $param['param']['add_bonus'];                          //add_bonus
                $option['bd_cate'] = 'bonus';
                $option['type'] = 1;//变动 1增加 2减少
                $option['cate'] = 1;  //变动类型
                $option['pay_cate'] = 4; //支付方式
                $option['source'] = 'web';  //来源
                $option['remark'] = $param['param']['remark']; //备注                   //remark
                $option['action_user'] = $param['param']['action_user'];//操作人        //action_user
                $Fztest = new WnCardObj($option);
                $res = $Fztest->init();
                $datass[$k]['info'] = json_encode($res,JSON_UNESCAPED_UNICODE);

            }

            return 'success';
        }
    }


    private function task_biz_fenzhang($data = ''){

        // 1.当前任务将由哪个类来负责处理。
        //   当轮到该任务时，系统将生成一个该类的实例，并调用其 fire 方法
        $jobHandlerClassName  = 'app\merchant\job\Fenzhang';
        // 2.当前任务归属的队列名称，如果为新队列，会自动创建
        $jobQueueName  	  = "task_biz_fenzhang";
        // 3.当前任务所需的业务数据 . 不能为 resource 类型，其他类型最终将转化为json形式的字符串
        //   ( jobData 为对象时，需要在先在此处手动序列化，否则只存储其public属性的键值对)
        $jobData = $data ;
        // 4.将该任务推送到消息队列，等待对应的消费者去执行
        $isPushed = Queue::push( $jobHandlerClassName , $jobData , $jobQueueName );
        // database 驱动时，返回值为 1|false  ;   redis 驱动时，返回值为 随机字符串|false
        if( $isPushed !== false ){
            return 'success';
        }else{
            return 'error';
        }
    }
//        $Fitlist = new ProfitList();
//        $Paylog = new Paylog();
////        $map['mid'] = 1026;
//        $map['mid'] = 1026;
//        $fitlist = $Fitlist->where($map)->field('orderid')->select();
//        foreach ($fitlist as $k=>$v){
//            $payinfo = $Paylog->where('orderid',$v['orderid'])->field('orderno,price')->find();
//            $data['orderno'] = $payinfo['orderno'];
//            $sxf = number_format((6/1000)*$payinfo['price'],2);
//            $data['price'] = $payinfo['price'] - $sxf;
//            $Fitlist->save($data,['orderid'=>$v['orderid']]);
//        }
//核销积分  无通知
    public function hxbonusnotz()
    {

        $id = 332052;
        $CardUserGet = new CardUserGet();
        $map['id'] = $id;
        $user = $CardUserGet->where($map)->find();
        $options = $this->options($user['card_id']);
        $WxObj = new Wxobjopen($options);
        $data['code'] = $user['code'];
        $data['card_id'] = $user['card_id'];
        $data['bonus'] = 0;
        $data['notify_optional']['is_notify_bonus'] = false;
        $data['notify_optional']['is_notify_balance'] = false;
        $data['notify_optional']['is_notify_custom_field1'] = false;
        $res = $WxObj->updateUserInfo($data);
        return json($res);
    }




    public function payregsgive($param)
    {


        $CardPaycard = new CardPaycard();
        $giveid = $param['giveid'];
        $zs_card = $CardPaycard->where('id', $giveid)->value('cardlist');
        $card_no = count(json_decode($zs_card, true));

        if ($card_no > 0) {
            $arr['zs_card_id_all'] = $zs_card;
            $arr['openid'] = $param['openid'];
            $arr['code'] = $param['code'];
            $arr['mid'] = $param['mid'];
            $arr['card_id'] = $param['card_id'];
            $arr['give_rec_id'] = $param['give_rec_id'];
            $arr['top_mid'] = $param['top_mid'];

            $res = $this->pay_zs_cardslog($arr);
            if ($res) {
                $SendMsg = new TemplateMsg();
                $arrs['mid'] = $arr['mid'];
                $arrs['openid'] = $arr['openid'];
                $arrs['card_id'] = $arr['card_id'];
                $arrs['name'] = $param['nickname'];
                $arrs['title'] = '卡券购买';
                $arrs['give_id'] = $giveid;
                $arrs['type'] = 'paycard';
                $arrs['url'] = '/mobile.php?s=/cardget/getpaycards/card_id/' . $arr['card_id'] . '/rec_id/' . $arr['give_rec_id'];
                $resu = $SendMsg->send_tpl('put_gift', $arrs);
            } else {
                $resu = '';
            }
            $resut['card'] = $resu;
            $datac['giveinfo'] = json_encode($resut, JSON_UNESCAPED_UNICODE);
            $datac['paystatu'] = 1;
            $datac['paytime'] = time();
            $CardPaycardlog = new CardPaycardlog();
            $CardPaycardlog->allowField(true)->save($datac, ['id' => $param['give_rec_id']]);
            $CardPaycard->where(['id' => $giveid])->setInc('get_num');
        } else {
            $resut['card'] = '无券赠送';
        }

        return $resut;
    }

    public function pay_zs_cardslog($arr)
    {
        $CardGivecardLog = new CardGivecardLog();
        $zs_card_id = $arr['zs_card_id_all'];
        if ($zs_card_id) {
            $zs_card_id = json_decode($arr['zs_card_id_all'], true);
            $data = [];
            foreach ($zs_card_id as $k => $v) {
                $is_pay = filterispay($v['zs_card_id']);
                $is_off = filteroffcard($v['zs_card_id']);
                if ($is_pay == true && $is_off == true) {
                    $data[$k]['card_id'] = $arr['card_id'];
                    $data[$k]['openid'] = $arr['openid'];
                    $data[$k]['code'] = $arr['code'];
                    $data[$k]['zs_card_id'] = $v['zs_card_id'];
                    $data[$k]['give_rec_id'] = $arr['give_rec_id'];
                    $data[$k]['mid'] = $arr['mid'];
                    $data[$k]['top_mid'] = $arr['top_mid'];
                    $data[$k]['put_sume'] = $v['zs_no'];
                    $data[$k]['put_type'] = 'paycard';
                    $data[$k]['create_time'] = time();
                }
            }
            $res = $CardGivecardLog->saveAll($data);
        } else {
            $res = '';
        }
        return $res;
    }

    public function tests(){
        $arr['username'] = 'san';
        $LoginUsers = new LoginUsers();
        $result = $LoginUsers->validate(
            [
                'username'=>'unique:loginusers|min:6',
            ],
            [
                'username.unique'=>'用户名已存在',
                'username.min'     => '用户名不可小于6位',
            ]
        )->save($arr);
        if(false === $result){
            // 验证失败 输出错误信息
            dump($LoginUsers->getError());
        }
    }

    public function getwxstoreinfo(){
        $data['poi_id'] = '477788305';
        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
        $options= $this->options($card_id);
        $weObj = new Wxobjopen($options);
        $res = $weObj->getStoreInfoApp($data);
        return json($res);

    }

    public function consumestatu(){
        $card_id = "pmh7V1BiUNpXBgbj0otCP0zJByVY";
        $code = "533776555400";
        $data = [
            'card_id' => $card_id,
            'code' => $code,
            'check_consume' => true
        ];
        $options = $this->options($card_id);
        $wxObj = new Wxobjopen($options);
        $res = $wxObj->getCardState($data);
        return json($res);
        if ($res['errcode'] == 0){
            return '0';
        }else{
            return '1';
        }
    }

    public function getcardinfowx()
    {
        $card_id = request()->param('card_id');
        if ($card_id && $this->checkcardid($card_id)) {
            $data = [
                "card_id" => $card_id
            ];
            $options = $this->options($card_id);
            $wxObj = new Wxobjopen($options);
            $res = $wxObj->getCardInfo($data);
            return json($res);
        }
    }

    public function test(){
        $orderid = "H501-20190124150419688003";
        $AfterPayPutCard = new AfterPayPutCardTest();
        $res = $AfterPayPutCard->paymentcard($orderid);
        return json($res);
        var_dump($res);
    }

//    public function test(){
//        Debug::remark('begin');
////        $map['card_id'] = '';
//        $map['a.card_type'] = ['neq',"MEMBER_CARD"];
//        $map['a.statu'] = ['neq',2];
//        $map['a.type_time'] = null;
//        $CardUserGet = new CardUserGet();
//        $num = $CardUserGet->alias('a')->where($map)->count();
//        $list = $CardUserGet->alias('a')->join('wn_card_general b', 'a.c_id=b.id', 'left')->where($map)->field('a.id,a.card_id,a.c_id,b.time_type')->limit(0,10000)->select();
//        var_dump($num);
//        foreach ($list as $k=>$v){
//            $data[$k]['id'] = (int)$v['id'];
//            $data[$k]['type_time'] = $v['time_type'];
//        }
//        $CardUserGet->isUpdate()->saveAll($data);
//        Debug::remark('end');
//        echo Debug::getRangeTime('begin','end').'s';
//        return json($data);
//        $CardPaycardlog = new CardPaycardlog();
//        $updata['orderid'] = 'H501-2019010711061916954';
//        $arr['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $arr['code'] = '819240230226';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $arr['nickname'] = 'clear';
//        $arr['mid'] = 501;
//        $arr['give_rec_id'] = '26381';
//        $arr['giveid'] = $CardPaycardlog->where('orderid', $updata['orderid'])->value('fid');
//        $arr['id'] = '4457';
//        $arr['top_mid'] = 1;
//        $res = $this->payregsgive($arr);
//        var_dump($res);
//        try {

//            $map['code'] = $param['code'];
//            $CardUserGet = new CardUserGet();
//            $user = $CardUserGet->where($map)->field('id,code,outerstr,sourec,card_id')->find();
//            if ($user) {
//                //为空时或支付后送券则更新归属为创建门店
//                if ($user['outerstr'] == '' || $user['outerstr'] == null || $user['sourec'] == "SOURCE_SCENE_TPMSG_SEND_MEMBER_AFTER_PAY") {
//                    $CardMember = new CardMember();
//                    $sql['card_id'] = $user['card_id'];
//                    $card = $CardMember->where($sql)->field('mid')->find();
//                    //END
//                    $data['gs_mid'] = $card['mid'];
//                    $CardUserGet->save($data, $map);
//                    $result = 'success';
//                } else {
//                    //不为空时
//                    //是否有规则
//                    if (strpos($user['outerstr'], '_')) {
//                        $CardShareUser = new CardShareUser();
//                        $top_user_s = $CardShareUser->where(['card_id' => $user['card_id'], 'outerstr' => $user['outerstr']])->field('code,openid')->find();
//                        //查找分享用户
//                        if ($top_user_s) {
//                            $top_user = $CardUserGet->where(['code' => $top_user_s['code']])->field('id,code,outerstr,sourec,card_id,gs_mid')->find();
//                            //分享用户是否领卡
//                            if ($top_user) {
//                                //分享用户是否又归属门店
//                                if ($top_user['gs_mid']) {
//                                    $data['gs_mid'] = $top_user['gs_mid'];
//                                    $CardUserGet->save($data, $map);
//                                    $result = 'success';
//                                } else {
//                                    $result = 'error';
//                                }
//                            } else {
//                                $result = 'error';
//                            }
//                        } else {
//                            $result = 'error';
//                        }
//                    } else {
//                        //小于五位时更新归属为场景值
//                        if (strlen($user['outerstr']) < 5 && is_numeric($user['outerstr'])) {
//                            $data['gs_mid'] = $user['outerstr'];
//                            $CardUserGet->save($data, $map);
//                            $result = 'success';
//                        } else {
//                            $result = 'error';
//                        }
//                    }
//                }
//                //是否更新归属门店成功
//                if ($result == 'error') {
//                    $CardMember = new CardMember();
//                    $sql['card_id'] = $user['card_id'];
//                    $card = $CardMember->where($sql)->field('mid')->find();
//                    //END
//                    $data['gs_mid'] = $card['mid'];
//                    $CardUserGet->save($data, $map);
//                    $result = 'success';
//                }
//
//            }

//        }catch (\Exception $e) {
//            $res = json_encode(array('code' => '9099', 'message' => $e->getMessage()));
//
//            $ActionLogs=new ActionLogs();
//            $ActionLogs->writelog("payos","wxcard","gs_mid","e:",$res);
//        }

//    }
    public function delcardus()
    {
        $card_id = "pCVCLv9UcfbrJBX-7YKXZZQaggd4";

        $CardMember = new CardMember();
        $data['card_id'] = $card_id;
        //初始化微信API
        $options = $this->options($card_id);
        $wxObj = new Wxobjopen($options);
        $res = $wxObj->delUserCard($data);
        if ($res['errcode'] == 0) {
            $CardUserFee = new CardUserFee();
            $CardUserBonus = new CardUserBonus();
            $CardUserGet = new CardUserGet();
            $CardUpdate = new CardUserUpdate();
            $CardGivecardLog = new CardGivecardLog();
            $CardMember->where($data)->delete();
            $CardGivecardLog->where($data)->delete();
            $CardUpdate->where($data)->delete();
            $CardUserGet->where($data)->delete();
            $CardUserFee->where($data)->delete();
            $CardUserBonus->where($data)->delete();
            return json($res);
            $this->success('删除成功', 'cardus/carduslist', '', 1);
        } else {
            //错误提示翻译
            $Helpinfo = new Helpinfo();
            $errmsg = $Helpinfo->gethelpinfo(0,$res['errcode'],$res['errmsg']);
            //END
            $this->error('删除失败-'.$res['errcode'].':' . $errmsg, 'cardus/carduslist', '', 3);
        }

    }

    public function delcardususer(){
        $card_id = 'pCVCLv9UcfbrJBX-7YKXZZQaggd4';
        $CardUserGet = new CardUserGet();
        $map['card_id'] = $card_id;
        $list = $CardUserGet->where($map)->select();
        $options = $this->options($card_id);
        $wxObj = new Wxobjopen($options);
        $res=[];
        foreach ($list as $k=>$v){
            $data['card_id'] = $v['card_id'];
            $data['code'] = $v['code'];

            $data['reason'] = '测试卡删除';
//            var_dump($data);
            $res[] = $wxObj->delineUserCard($data);
        }
        return json($res);

    }
//    public function tests(){
//        Debug::remark('begin');
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['gs_mid'] = 0;
//        $CardUserGet = new CardUserGet();
//        $user = $CardUserGet->where($map)->field('id,code')->limit(5000,5000)->select();
//        foreach ($user as $k=>$v){
//            $res = $this->test($v);
//            var_dump($res);
//        }
//        Debug::remark('end');
//        echo Debug::getRangeTime('begin','end').'s';
//    }



//    public function test(){
//        Debug::remark('begin');
//        $CardUserGet = new CardUserGet();
//        $map['card_type'] = ['neq','MEMBER_CARD'];
////        $map['id'] =['gt',1000];
//        $map['is_out'] = 0;
//        $map['end_time'] = ['lt',time()];
//        $list = $CardUserGet->where($map)->limit(0,20000)->field('id,code,card_id')->select();
////        $res = $CardUserGet->where($map)->count('id');
//        foreach ($list as $k=>$v){
//            //END
//            $data[$k]['id'] = (int)$v['id'];
//            $data[$k]['code'] = $v['code'];
//            $data[$k]['is_out'] = 1;
//        }
//        Debug::remark('end');
//
//        $CardUserGet->isUpdate(true)->saveAll($data);
//        echo Debug::getRangeTime('begin','end').'s';
//        return json($data);


//        $CardGen = new CardGeneral();
//        foreach ($list as $k=>$v){
//
//            $sql['card_id'] = $v['card_id'];
//            $sql['card_id'] = $v['card_id'];
//            $card = $CardGen->where($sql)->field('id,begin_timestamp,end_timestamp')->find();
//            if ($card) {
//                //END
//                $data[$k]['id'] = (int)$v['id'];
//                $data[$k]['c_id'] = $card['id'];
//
//                $data[$k]['code'] = $v['code'];
//                $data[$k]['card_id'] = $v['card_id'];
//                $data[$k]['start_time'] = $card['begin_timestamp'];
//                $data[$k]['end_time'] = $card['end_timestamp'];
//            }else{
//                $sqls['id'] = $v['id'];
//                $CardUserGet->where($sqls)->delete();
//            }
//        }
//        $CardTimingPutUser = new CardTimingPutUser();
//        $start_time = date('H') . ":00:00";
//        $end_time = date('H') . ":59:59";
//        $map['notice_time'] = array(array('egt', $start_time), array('elt', $end_time));
//        $map['statu'] = "N";
//        $CardTimingPutUser->toArray();
//        $list = $CardTimingPutUser->where($map)->select();
//        $list = collection($list)->toArray();
//        foreach ($list as $k => $v) {
//            var_dump($v);
//            $ress = $this->task_biz_putbirthday($v);
//            var_dump($ress);
////            $i = $k;
////            $lists[$k] = $v;
////            if ($i / 50 == 0 && $i > 0 ) {
////                $ress = $this->task_biz_putbirthday($v);
////                $e = $i;
////            }
////
////            if ($total - $e < 50) {
////                $ress = $this->task_biz_putbirthday($v);
////            }
//        }




//        $Paylog = new Paylog();
//        $orderid = 'H501-2018122917293347940';
//        $id = $Paylog->where('orderid',$orderid)->find();
//        if ($id['pay_cate'] == "支付") {
//            $paymentcards['orderid'] = $id['orderid'];
//            $paymentcards['openid'] = $id['openid'];
//            $paymentcards['add_time'] = $id['add_time'];
//            $paymentcards['price'] = $id['price'];
//            $paymentcards['mid'] = $id['mid'];
//            $paymentcards['pay_fs'] = $id['pay_fs'];
//            $Wxpay = new \app\index\controller\Wxpay();
//            $res = $Wxpay->payment_card_put($paymentcards);
//        }
//        $res = '1';
//        var_dump($res);
//        $CardBrd = new CardBirthdayCareLog();
//        $list = $CardBrd->select();
//        foreach ($list as $k=>$v){
//                $data[$k]['create_time'] = $v['create_time'];
//        }
//        return json($data);
//        $ares['qweqwe'] = 'qweqweqw';     statis_time
//        $res = file_put_contents('/data2/html/actionlog/payos/wxcard/cardobj/2018-12-29.txt', '3:' . json_encode($ares) . PHP_EOL, FILE_APPEND);
//        var_dump($res);
//        $arrs['rec_id'] = 31146;
//        $arrs['card_id'] = 'pePs8v3mm3nHv2YmOVceVeLllNvI';
//        $arrs['code'] = "472162474056";
//        $arrs['username'] = "王玲";
//        $arrs['giveid'] = 314;
//        $arrs['orderid'] = "H722-2018122910024020542";
//        $arrs['add_balance'] = 180;
//        $Wxpay = new \app\index\controller\Wxpay();
//        $resut = $Wxpay->cz_bonus_fee($arrs);
//        return $resut;
//        $CardUserGet = new CardUserGet();
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['birthday'] = ['neq',''];
//        $map['feteday'] = null;
//        $res = $CardUserGet->where($map)->count();
////        var_dump($res);
////        exit();
//        $list = $CardUserGet->where($map)->field('birthday,id,feteday')->select();
//
//        foreach ($list as $k=>$v){
//            $maps['id'] = (int)$v['id'];
//            $data['feteday'] = $birthday = date("m-d", strtotime($v['birthday']));
//            $res = $CardUserGet->save($data,$maps);
//            var_dump($res);
//        }
//        $res = $CardUserGet->saveAll($data);
//        return json($res);

//        $res = strtotime("+99 year");
//        var_dump($res);
//        $data = '{
//	"ToUserName": "gh_7cce5f015893",
//	"FromUserName": "oCVCLv2epPfR-zgO8v3HE7y5yjsw",
//	"CreateTime": "1545668493",
//	"MsgType": "event",
//	"Event": "unsubscribe",
//	"EventKey": {}
//}';
//        $datas = json_decode($data,true);
//        $datas['gh_id'] = $datas['ToUserName'];
//        $datas['openid'] = $datas['FromUserName'];
//        $datas['createtime'] = $datas['CreateTime'];
//        $datas['click_key'] = 'matter_free_55';
//        $CardPut = new CardPuttest();
//        $newsdata = $CardPut->clickmenuputcard($datas);
//        var_dump($newsdata);
//        $data['rule_id'] = '18';
//        $data['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $data['get_code'] = '118305266158';
//        $data['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $res = $this->getsharecards($data);
//        var_dump($res);

//        $data['lid'] = '176';
//        $data['gid'] = '442369';
//        $res = $this->getRankReward($data);
//        var_dump($res);

//    }


//    public function getRankReward(){
//        if (Request()->isAjax()){
//            $arr = request()->post();      //获取参数
//            $CardRank = new CardRank();
//            $CardUserGet = new CardUserGet();
//            $map['id'] = $arr['gid'];
//            $user = $CardUserGet->where($map)->field('growup,bonus,openid,code,card_id,rank_lock,balance,c_id,id,nickname,top_mid,mid')->find();  //会员信息
//            $isarr['lid'] = $arr['lid'];
//            $isarr['user_growup'] = $user['growup'];
////            return $isarr;
//            $is_rank = $this->is_rank_new($isarr);      //等级判断
//            if ($is_rank == 0){
//                $rank = $CardRank->where(['id'=>$arr['lid']])->find();     //等级奖励
////                $level = getlive($user['card_id'],$user['bonus']);  //是否已领取
//                if ($user['rank_lock'] < $rank['live']){
//                    if ($rank['reward_bonus'] > 0 || $rank['reward_balance'] >0 || $rank['zs_card_id_all'] !== '') {
//                        $CardRankUserLog = new CardRankUserLog();
//                        $data['c_id'] = $user['c_id'];
//                        $data['us_c_id'] = $user['id'];
//                        $data['level'] = $rank['live'];
//                        $data['card_id'] = $user['card_id'];
//                        $data['code'] = $user['code'];
//                        $data['openid'] = $user['openid'];
//                        $data['bonus'] = $rank['reward_bonus'];
//                        $data['balance'] = $rank['reward_balance'];
//                        $data['cards'] = json_encode($rank['zs_card_id_all']);
//                        $users = $CardRankUserLog->allowField(true)->save($data);
//                        $rec_id = $CardRankUserLog->id;
//
//                        $marke = new \app\mobile\controller\Cardmarke();
//                        if ($rank['reward_bonus'] > 0 && $rank['is_bonus'] =="Y"){
//                            $bonus['card_id'] = $user['card_id'];
//                            $bonus['code'] = $user['code'];
//                            $bonus['openid'] = $user['openid'];
//                            $bonus['add_bonus'] = $rank['reward_bonus'];
//                            $bonus['name'] = '等级奖励';
//                            $bonus['outerstr'] = '等级奖励';
//                            $resbonus = $marke->varybonus($bonus);
//                        }else{
//                            $resbonus = 0;
//                        }
//                        if ($rank['reward_balance'] > 0 && $rank['is_balance'] =="Y"){
//                            $balance['card_id'] = $user['card_id'];
//                            $balance['code'] = $user['code'];
//                            $balance['openid'] = $user['openid'];
//                            $balance['add_balance'] = $rank['reward_balance'];
//                            $balance['name'] = '等级奖励';
//                            $balance['type'] = '3';
//                            $balance['balance'] = $user['balance'] + $rank['reward_balance'];
//                            $balance['outerstr'] = '等级奖励';
//                            $resbalance = $marke->varybanlance($balance);
//                        }else{
//                            $resbalance = 0;
//                        }
//                        if ($rank['zs_card_id_all'] !== '' && $rank['is_cards'] =="Y"){
//                            $cards['card_id'] = $user['card_id'];
//                            $cards['remark'] = $rank['live_title'];
//                            $cards['zs_card_info'] = $rank['zs_card_info'];
//                            $cards['zs_card_id_all'] = $rank['zs_card_id_all'];
//                            $cards['code'] = $user['code'];
//                            $cards['openid'] = $user['openid'];
//                            $cards['nickname'] = $user['nickname'];
//                            $cards['rec_id'] = $rec_id;
//                            $cards['top_mid'] = $user['top_mid'];
//                            $cards['mid'] = $user['mid'];
//                            $rescard = $marke->varycards($cards);
//                        }else{
//                            $rescard = 0;
//                        }
//
//
//                        if ($resbalance == 0 && $resbonus == 0 && $rescard == 0){
//                            $ldata['rank_lock'] = $rank['live'];
//                            $CardUserGet->save($ldata,$map);
//                            $rarr['code'] = 0;
//                            $rarr['message'] = '领取成功';
//                        }else{
//                            $rarr['code'] = 0;
//                            $rarr['message'] = '领取失败';
//                        }
//                    }else{
//                        $rarr['code'] = 9003;
//                        $rarr['message'] = '无奖励';
//                    }
//                }else{
//                    $rarr['code'] = 9002;
//                    $rarr['message'] = '已领取';
//                }
//            }else{
//                $rarr['code'] = 9001;
//                $rarr['message'] = '未达到';
//
//            }
//            return json($rarr);
//        }
//    }

//等级判断
//    private function is_rank_new($arr){
//        $CardRank = new CardRank();
//        $map['id'] = $arr['lid'];
//        $rank = $CardRank->where($map)->find();
//        if ($rank['growup'] <= $arr['user_growup']){
//            $data = 0;      //达到
//        }else{
//            $data = 1;      //未达到
//        }
//        return $data;
//    }
//
//
//    //分享领取奖励余额
//    public function getsharecards($arrs)
//    {
//        try{
//            $CardShareRule = new CardShareRule();
//            $ruleinfo = $CardShareRule->where(['id' => $arrs['rule_id']])->find();
//            if ($ruleinfo['zs_no'] > 0) {
//                $data['card_id'] = $arrs['card_id'];
//                $data['openid'] = $arrs['openid'];
//                $CardUserGet = new CardUserGet();
//                $user = $CardUserGet->where($data)->field('top_mid,mid,code,openid,nickname')->find();
//                $data['get_code'] = $arrs['get_code'];
//                $data['top_mid'] = $user['top_mid'];
//                $data['code'] = $user['code'];
//                $data['mid'] = $user['mid'];
//                $data['openid'] = $user['openid'];
//                $data['nickname'] = $user['nickname'];
//                $res['cards'] = $this->sharecards($data,$ruleinfo);
//            }else{
//                $res['cards'] = '';
//            }
//            return $res;
//        } catch (\Exception $e) {
//            $res = json_encode(array('code' => '9099', 'message' => $e->getMessage()));
//            $ActionLogs=new ActionLogs();
//            $ActionLogs->writelog("payos","wxcard","share_balance","e:",$res);
//        }
//    }
//
//
//    //开卡送券
//    //arr:user  code  card_id  mid  openid  nickname    share:shareinfo  zs_card_info  zs_card_id_all
//    public function sharecards($param,$share)
//    {
//
//        $CardShareLog = new CardShareLog();
//
//        $data['zs_card_info'] = $share['zs_card_info'];
//        $data['share_info'] = json_encode($share,JSON_UNESCAPED_UNICODE);
//        $map['get_code'] = $param['get_code'];
//        $map['card_id'] = $param['card_id'];
//        $give_rec_id = $CardShareLog->where($map)->value('id');
//        if ($give_rec_id) {
//            $CardShareLog->allowField(true)->save($data, $map);
//
//
//            $param['give_rec_id'] = $give_rec_id;
//            $res = $this->get_share_cardslog($param, $share);
//            if ($res) {
//                $CardUserGet = new CardUserGet();
//                $Momchant = new Momerchant();
//                $getuser = $CardUserGet->where()->field('nickname,top_mid')->find();
//                $Momach = $Momchant->where('id',$getuser['top_mid'])->field('merchant_name')->find();
//                //END
//                $SendMsg = new TemplateMsgt();
//                $arrs['first'] = '您好,您的好友@'.$getuser['nickname'].'通过邀请成为了'.$Momach['merchant_name'].'会员，邀请奖励已放入您的会员卡,请查收~';
//                $arrs['mid'] = $param['mid'];
//                $arrs['openid'] = $param['openid'];
//                $arrs['name'] = $param['nickname'];
//                $arrs['title'] = $share['zs_card_info'];
//                $arrs['card_id'] = $param['card_id'];
//                $arrs['rec_id'] = $give_rec_id;
//                $arrs['type'] = 'sharecard';
//                $arrs['url'] = '/mobile.php?s=/cardgettest/getsharecards/card_id/' . $param['card_id'] . '/rec_id/' . $give_rec_id;
//                $resu = $SendMsg->send_tpl('put_gift', $arrs);
//            } else {
//                $resu = '';
//            }
//        }else{
//            $resu = '';
//        }
//        return $resu;
//    }
//
//
//
//    //开卡送券记录
//    public function get_share_cardslog($param,$share){
//        $CardGivecardLog = new CardGivecardLog();
//        $zs_card_id = $share['zs_card_id_all'];
//        if ($zs_card_id){
//            $zs_card_id = json_decode($share['zs_card_id_all'],true);
//            $data = [];
//            foreach ($zs_card_id as $k=>$v) {
//                $data[$k]['card_id'] = $param['card_id'];
//                $data[$k]['code'] = $param['code'];
//                $data[$k]['openid'] = $param['openid'];
//                $data[$k]['zs_card_id'] = $v['zs_card_id'];
//                $data[$k]['give_rec_id'] = $param['give_rec_id'];
//                $data[$k]['mid'] = $param['mid'];
//                $data[$k]['top_mid'] = $param['top_mid'];
//                $data[$k]['put_sume'] = $v['zs_no'];
//                $data[$k]['put_type'] = 'share_card';
//                $data[$k]['create_time'] = time();
//            }
//
//            $res = $CardGivecardLog->saveAll($data);
//        }else{
//            $res = '';
//        }
//        return $res;
//    }
//
//
//
//    public function shengri()
//    {
//        $CardBirthdayCare = new CardBirthdayCare();
//        $map['statu'] = 1;
//
//        $carelist = $CardBirthdayCare->where($map)->select();
//        $carelists = [];
//        foreach ($carelist as $k=>$v){
//            if ($v['time_type'] == 'lasting'){
//                $carelists[] = $v;
//            }
//            if ($v['time_type'] == 'range' && $v['end_time'] > time()){
//                $carelists[] = $v;
//            }
//        }
//
//        if ($carelists !== []) {
//            //END
//            $CardUserGet = new CardUserGet();
//            $CardTimingPutUser = new CardTimingPutUser();
//            foreach ($carelists as $k => $v) {
//                $riqi = date('m-d', strtotime(date('Y-m-d', time())) + $v['advance_day'] * 86400);       //时间
//                $maps['birthday'] = ['neq', ''];
//                $maps['top_mid'] = $v['top_mid'];
//                $maps['fire'] = 1;
//                $maps['have'] = 1;
//                $maps['card_type'] = 'MEMBER_CARD';
//                $userlist = $CardUserGet->where($maps)->field('c_id,mid,id,code,openid,card_id,birthday,nickname')->select();
//                $list = [];
//
//                foreach ($userlist as $ks => $vs) {
//                    $birthday = date("m-d", strtotime($vs['birthday']));
//                    if ($riqi == $birthday) {
//                        $list[$ks]['mid'] = $vs['mid'];
//                        $list[$ks]['code'] = $vs['code'];
//                        $list[$ks]['openid'] = $vs['openid'];
//                        $list[$ks]['name'] = $vs['nickname'];
//                        $list[$ks]['card_id'] = $vs['card_id'];
//                        $list[$ks]['birthday'] = $vs['birthday'];
//                        $list[$ks]['c_id'] = $vs['c_id'];
//                        $list[$ks]['us_c_id'] = $vs['id'];
//                        $list[$ks]['is_bonus'] = $v['is_bonus'];
//                        $list[$ks]['is_cards'] = $v['is_cards'];
//                        $list[$ks]['put_type'] = $v['put_type'];
//                        $list[$ks]['notice_time'] = $v['notice_time'];
//                        $list[$ks]['top_mid'] = $v['top_mid'];
//                        $list[$ks]['wx_open_id'] = $v['wx_open_id'];
//                        $list[$ks]['remark'] = $v['remark'];
//                        $list[$ks]['bonus'] = $v['bonus'];
//                        $list[$ks]['zs_card_id_all'] = $v['zs_card_id_all'];
//                        $list[$ks]['zs_card_info'] = $v['zs_card_info'];
//                        $list[$ks]['statu'] = 'N';
//                        $list[$ks]['send_type'] = 'BIRTHDAY_CARE';
//                        $list[$ks]['user_info'] = json_encode($vs);
//                        $list[$ks]['create_time'] = time();
//                    }
//                }
//
//                if ($list !== []) {
//                    $CardTimingPutUser->allowField(true)->saveAll($list);
//
//                }
//            }
//        }
//    }
//
//    public function sendsri(){
//        $CardTimingPutUser = new CardTimingPutUser();
//        $start_time = date('H') . ":00:00";
//        $end_time = date('H') . ":59:59";
//        $map['notice_time'] = array(array('egt', $start_time), array('elt', $end_time));
//        $map['statu'] = "N";
//
//        $CardTimingPutUser->toArray();
//        $list = $CardTimingPutUser->where($map)->select();
//        $list = collection($list)->toArray();
//        return json($list);
//        $total = count($list);
//        $e = 1;
//        $ress = [];
//        foreach ($list as $k => $v) {
//            $i = $k;
//            $lists[$k] = $v;
//            if ($i / 50 == 0 && $i > 0 ) {
//                $ress = $this->task_biz_putbirthday($v);
//                $e = $i;
//            }
//
//            if ($total - $e < 50) {
//                $ress = $this->task_biz_putbirthday($v);
//            }
//        }
//        var_dump($ress);
//
//
//        if ($arr['time_type'] == 'lasting'){
//            $data['start_time'] = time();
//            $data['end_time'] = strtotime("+99 year");
//        }else{
//            $times = explode(" - ", $arr['times']);
//            $data['start_time'] = $times[0];
//            $data['end_time'] = $times[1];
//        }
//    }
//
//
//    //发券
//    private function task_biz_putbirthday($data = ''){
//
//        // 1.当前任务将由哪个类来负责处理。
//        //   当轮到该任务时，系统将生成一个该类的实例，并调用其 fire 方法
//        $jobHandlerClassName  = 'app\merchant\job\Birthday';
//        // 2.当前任务归属的队列名称，如果为新队列，会自动创建
//        $jobQueueName  	  = "task_biz_birthdaycare";
//        // 3.当前任务所需的业务数据 . 不能为 resource 类型，其他类型最终将转化为json形式的字符串
//        //   ( jobData 为对象时，需要在先在此处手动序列化，否则只存储其public属性的键值对)
//        $jobData = $data ;
//        // 4.将该任务推送到消息队列，等待对应的消费者去执行
//        $isPushed = Queue::push( $jobHandlerClassName , $jobData , $jobQueueName );
//        // database 驱动时，返回值为 1|false  ;   redis 驱动时，返回值为 随机字符串|false
//        return $isPushed;
//        if( $isPushed !== false ){
//            return 'success';
//        }else{
//            return 'error';
//        }
//    }
//
//    //群发模版消息
//    public function task_put_user($data)
//    {
//        //积分
//        if ((int)$data['bonus'] > 0){
//            $option['card_id'] = $data['card_id'];
//            $option['code'] = $data['code'];
//            $option['orderid'] = '';
//            $option['num'] = $data['bonus'];
//            $option['bd_cate'] = 'bonus';
//            $option['type'] = 1;//变动 1增加 2减少
//            $option['cate'] = 1;  //变动类型
//            $option['pay_cate'] = 4; //支付方式
//            $option['source'] = 'web';  //来源
//            $option['remark'] = $data['remark']; //备注
//            $option['action_user'] = 'web';//操作人
//            $Fztest = new WnCardObj($option);
//            $res = $Fztest->init();
//            $CardTimingPutUser = new CardTimingPutUser();
//            if ($res){
//                $datas['statu'] = "Y";
//                $CardTimingPutUser->save($datas,['id'=>$data['id']]);
//            }else{
//                $datas['statu'] = "E";
//                $CardTimingPutUser->save($datas,['id'=>$data['id']]);
//            }
//        }
//        //发券
//        if ($data['zs_card_id_all'] !== ''){
//            $TemplateMesgt = new TemplateMsgt();
//            $rec_id = $this->rec_giveuserlog($data);
//            $data['first'] = $data['remark'].'点击“详情”领取优惠券';
//            if (strpos($data['zs_card_info'],"赠卡券：") !== false){
//                $data['zs_card_info'] = str_replace("赠卡券：",'',$data['zs_card_info']);
//            }
//            $data['title'] = $data['zs_card_info'];
//            $data['type'] = 'birthdaycare';
//            $data['url'] = '/mobile.php?s=/cardgettest/getcardsbirthdaycare/mid/' . $data['mid'] . '/rec_id/' . $rec_id;
//            $res = $TemplateMesgt->send_tpl('put_gift',$data);
//            $CardTimingPutUser = new CardTimingPutUser();
//            if ($res['errcode'] == 0){
//                $datas['statu'] = "Y";
//                $CardTimingPutUser->save($datas,['id'=>$data['id']]);
//            }else{
//                $datas['statu'] = "E";
//                $CardTimingPutUser->save($datas,['id'=>$data['id']]);
//            }
//        }
//    }
//
//    private function rec_giveuserlog($arr){
//        $CardBirthdayCareLog = new CardBirthdayCareLog();
//        $datas['top_mid'] = $arr['top_mid'];
//        $datas['mid'] = $arr['mid'];
//        $datas['c_id'] = $arr['c_id'];
//        $datas['us_c_id'] = $arr['us_c_id'];
//        $datas['card_id'] = $arr['card_id'];
//        $datas['openid'] = $arr['openid'];
//        $datas['code'] = $arr['code'];
//        $datas['remark'] = $arr['remark'];
//        $datas['bonus'] = $arr['bonus'];
//        $datas['user_info'] = $arr['user_info'];
//        $datas['put_type'] = 'birthdaycare';
//        $datas['statu'] = 'N';
//        $datas['zs_card_id_all'] = $arr['zs_card_id_all'];
//        $datas['zs_card_info'] = $arr['zs_card_info'];
//        $datas['create_time'] = time();
//        $CardBirthdayCareLog->allowField(true)->save($datas);
//        $give_rec_id = $CardBirthdayCareLog->id;
//        $zs_card_id = $arr['zs_card_id_all'];
//        if ($zs_card_id){
//            $CardGivecardLog = new CardGivecardLog();
//            $zs_card_id = json_decode($arr['zs_card_id_all'],true);
//            $data = [];
//            foreach ($zs_card_id as $k => $v) {
//                $data[$k]['c_id'] = $arr['c_id'];
//                $data[$k]['us_c_id'] = $arr['us_c_id'];
//                $data[$k]['card_id'] = $arr['card_id'];
//                $data[$k]['openid'] = $arr['openid'];
//                $data[$k]['code'] = $arr['code'];
//                $data[$k]['put_type'] = 'birthdaycare';
//                $data[$k]['zs_card_id'] = $v['zs_card_id'];
//                $data[$k]['give_rec_id'] = $give_rec_id;
//                $data[$k]['mid'] = $arr['mid'];
//                $data[$k]['top_mid'] = $arr['top_mid'];
//                $data[$k]['put_sume'] = $v['zs_no'];
//                $data[$k]['create_time'] = time();
//            }
//            $res = $CardGivecardLog->allowField(true)->saveAll($data);
//        }else{
//            $res = 0;
//        }
//        return $give_rec_id;
//    }
//
//    public function option($wx_open_id)
//    {
//        $System = new System();
//        $WxOpen = new WxOpen();
//        $config = $System->where(['id' => 1])->find();
//        $users = $WxOpen->where(['id' => $wx_open_id])->find();
//        $options = array(
//            'component_token' => $config['component_token'], // 填写你设定的key
//            'component_encodingaeskey' => $config['component_encodingaeskey'], // 填写加密用的EncodingAESKey
//            'component_appid' => $config['component_appid'], // 填写高级调用功能的app id
//            'component_appsecret' => $config['component_appsecret'], // 填写高级调用功能的密钥
//            'open_ticket' => $config['open_ticket'],
//            'authorizer_appid' => $users['authorizer_appid'],
//            'authorizer_refresh_token' => $users['authorizer_refresh_token'],
//        );
//        return $options;
//    }

//发券
//    private function task_biz_putbirthday($data = ''){
//
//        // 1.当前任务将由哪个类来负责处理。
//        //   当轮到该任务时，系统将生成一个该类的实例，并调用其 fire 方法
//        $jobHandlerClassName  = 'app\merchant\job\birthday';
//        // 2.当前任务归属的队列名称，如果为新队列，会自动创建
//        $jobQueueName  	  = "task_biz_birthdaycare";
//        // 3.当前任务所需的业务数据 . 不能为 resource 类型，其他类型最终将转化为json形式的字符串
//        //   ( jobData 为对象时，需要在先在此处手动序列化，否则只存储其public属性的键值对)
//        $jobData = $data ;
//        // 4.将该任务推送到消息队列，等待对应的消费者去执行
//        $isPushed = Queue::push( $jobHandlerClassName , $jobData , $jobQueueName );
//        // database 驱动时，返回值为 1|false  ;   redis 驱动时，返回值为 随机字符串|false
//        if( $isPushed !== false ){
//            return 'success';
//        }else{
//            return 'error';
//        }
//    }

//    public function sendbiz(){
//
////        [4458,4458,4458,4458,4458,4458,4458,4458,4458,4458,
////            4458,4458,4458,4458,4458,4458,4458,4458,4458,4458,
////            4458,4458,4458,4458,4458,4458,4458,4458,4458,4458,
////            4458,4458,4458,4458,4458,4458,4458,4458,4458,4458,
////            4458,4458,4458,4458,4458,4458,4458,4458,4458,4458];
//
//        $data['card_id'] = 'pVPrBjt54SC1Oj_bc1dsCQiMNtW8';
//        $data['add_bonus'] = 1;
//        $data['senduserlist'] = 259736;
//
//        $data['text'] = '文本编辑器文本编辑器文本编辑器文';
//        $res = $this->sendbonusbizcard($data);
////        var_dump($res);
//    }
//
//    public function sendbonusbizcard($param)
//    {
//
//        $CardBizPut = new CardBizPut();
////        $top_mid = Session::get('login_top_mid');
//        $top_mid = 154;
//        $map['top_mid'] = $top_mid;
//        $bizinfo = $CardBizPut->where(['top_mid' => $top_mid])->find();
//        $CardBizPutLogMember = new CardBizPutLogMember();
//        if ($bizinfo) {
//            $Platurl = new Platurl();
//            $url['platurl'] = $Platurl->getagenturl('top_mid', Session::get('login_top_mid'));
//            $cardlist = json_decode($bizinfo['card_id_list'], true);
//            $card = [];
//            foreach ($cardlist as $k => $v) {
//                if ($v['zs_no'] > $k && count($card) < 5) {
//                    $card[] = $v['zs_card_id'];
//                }
//            }
//            $cards = $card;
//            $data['card_id'] = $bizinfo['card_id'];
//            $data['member_card']['modify_msg_operation']['url_cell']['card_id_list'] = $cards;
//            $data['member_card']['modify_msg_operation']['url_cell']['end_time'] = $bizinfo['end_time'];
//            $data['member_card']['modify_msg_operation']['url_cell']['text'] = $param['text'];
//            $data['member_card']['modify_msg_operation']['url_cell']['url'] = $url['platurl'] . '/mobile.php?s=/cardget/getbizcard/give_id/' . $bizinfo['id'];
//            $data11['card_id'] = $bizinfo['card_id'];
//            $data11['data'] = json_encode($data,JSON_UNESCAPED_UNICODE);
//            $CardBizPutLogMember->allowField(true)->save($data11);
//            $cardlogmember_id = $CardBizPutLogMember->id;
//            //END
//            $res['errcode'] = 0;
//            //END
//            if ($res['errcode'] == 0) {
//                //存储
//                $dates['put_info'] = json_encode($data, JSON_UNESCAPED_UNICODE);
//                $resu = $CardBizPut->save($dates, ['id' => $bizinfo['id']]);
//                if ($resu) {
////                    var_dump($param);
////                    var_dump($bizinfo);
////                    var_dump($data);
////                    var_dump($cardlogmember_id);
////                    exit();
//                    $ress = $this->rec_sendbonusbizlog($param,$bizinfo,$data,$cardlogmember_id);
//                    exit();
//                    if ($ress == 0) {
//                        $rarr['code'] = 0;
//                        $rarr['message'] = '成功';
//                    } else {
//                        $rarr['code'] = 9001;
//                        $rarr['message'] = '失败';
//                    }
//                } else {
//                    $rarr['code'] = 9001;
//                    $rarr['message'] = '失败';
//                }
//            } else {
//                //错误提示翻译
//                $Helpinfo = new Helpinfo();
//                $errmsg = $Helpinfo->gethelpinfo(0, $res['errcode'], $res['errmsg']);
//                $rarr['code'] = 9002;
//                $rarr['message'] = $res['errcode'] . $errmsg;
//            }
//        } else {
//            $rarr['code'] = 9004;
//            $rarr['message'] = '请设置后再进行群发';
//        }
//        return json($rarr);
//
//    }
//
//    //增加积分执行跟随推荐
//    /*
//     * param :sql card_id add_bonus
//     *
//     * bizinfo : id  card_id_list c_id_list
//     *
//     */
//    public function rec_sendbonusbizlog($param, $bizinfo,$data,$cardlogmember_id)
//    {
////        $user = ["code" => 938482966806,"id" =>4458,"c_id" => 138,"mid" =>501,"openid" => "oCVCLv4uiIZlnKFPbMPRWJBlXdgo"];
////        $user = ["code" => 819240230226,"id" =>4457,"c_id" => 138,"mid" =>501,"openid" => "oCVCLv2epPfR-zgO8v3HE7y5yjsw"];
//        $user = ["code" => '070690810847',"id" =>259736,"c_id" => 251,"mid" =>727,"openid" => "oVPrBjlMYIwj1FqcsNbcdPVBdObY"];
//        $userlist = [];
//        $totals = 10;
//        for ($is=0;$is<$totals;$is=$is+1){
//            $userlist[] = $user;
//        }
//
//        $CardUserGet = new CardUserGet();
//        $map['id'] = array('in', $param['senduserlist']);
//        //队列
//        $sdata['param'] = $param;
//        $sdata['data'] = $data;
//        $sdata['param']['card_id'] = $param['card_id'];
//        $sdata['param']['action_user'] = Session::get('user.nickname');
//        $sdata['param']['add_bonus'] = $param['add_bonus'];
//        $sdata['param']['top_mid'] = Session::get('login_top_mid');
//        $sdata['bizinfo'] = $bizinfo;
//        $sdata['cardlogmember_id'] = $cardlogmember_id;
////        $total = $CardUserGet->where($map)->count();
//        $total = 1500;
//        $ress = '';
//        foreach ($userlist as $k=>$v){
//            $sdata['param']['userlist']  = [$v];
//            $ress = action('merchant/jobmach/task_biz_put', array($sdata));
//        }
////        foreach ($userlist as $k=>$v){
////
////        }
//
////   /     $map['id'] = '259736';
////        for ($i=0;$i<$total;$i=$i+50){
////
//////            $sdata['param']['userlist'][] = $CardUserGet->where($map)->field('code,id,c_id,mid,openid')->limit($i,100)->select();
////            $zzzdata[] = $CardUserGet->where($map)->field('code,id,c_id,mid,openid')->limit($i,50)->select();
////
////            $zzzdata = collection($zzzdata)->toArray();
////            var_dump($zzzdata);
//////            $sdata['param']['userlist']  = $userlist;
//////            $ress = action('merchant/jobmach/task_biz_put', array($sdata));
////        }
////        exit();
////        var_dump($map);
////        var_dump($zzzdata);
////        return json($zzzdata);
////        var_dump($sdata['param']['userlist']);
//        if ($ress == 'success') {
//            return 0;
//        } else {
//            return 1;
//        }
//    }
//
//    public function getranks(){
//        $top_mid = '"30","23","40","47","51","49","48","69","68","90","88","87","113","83","103","144","145","149","139","146","151","187","158","194","181","195","199","212","234","204","236","254","184"';
//        $CardUserGet = new CardUserGet();
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['top_mid'] = ['in',$top_mid];
//        $map['bonus'] = ['GT',0];
//        $num = $CardUserGet->where($map)->count('id');
//        var_dump($num);
//        exit();
//
//        $CardRank = new CardRank();
//        $CardMember = new CardMember();
//        $ranklist = $CardRank->field('card_id')->select();
//        foreach ($ranklist as $k=>$v){
//            $list[$k]['card_id'] = $v['card_id'];
//            if ($k > 0) {
//                if ($list[$k - 1]['card_id'] !== $v['card_id']) {
//                    $cardinfo = $CardMember->where('card_id', $v['card_id'])->value('top_mid');
//                    $lists[] = $cardinfo;
//                }
//            }
//        }
//
//        return json($lists);
//        var_dump(json($lists));
//    }
//
//    //自动更新会员卡自定义类目   第三类目
//    public function update_cell(){
//        $data['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $data['card_id'] = 'pCVCLv-baTR5kfNTKRou8MT6h7nY';
//        $data['code'] = '300756773564';
//        $data['cell_type'] = 'two_cell';            //类目类型   two_cell   three_cell
//        $CardCustom = new CardCustom();
//        $res = $CardCustom->carry_custom($data);
//        var_dump($res);
//
//    }
//
////    //
////    public function getuserfire(){
////
////
////    }
//    //检查是否有充值送券并获取链接
//    public function chackputurl(){
//        //   try {
//        $orderid = 'H501-2018112717304329254';
//
//        $Wxpay = new \app\index\controller\Wxpay();
//        $Paylog = new Paylog();
//        $CardCzLog = new CardCzLog();
//        $CardGivecardLog = new CardGivecardLog();
//        $CardUserGet = new CardUserGet();
//        $id = $Paylog->where('orderid', $orderid)->field('mid,openid,price,orderid,cz_card_id')->find();
//
//        //获得订单信息END
//        $updata['mid'] = $id['mid'];
//        $updata['openid'] = $id['openid'];
//        $updata['price'] = $id['price'];
//        $updata['orderid'] = $id['orderid'];
//        $updata['get_card_id'] = $id['cz_card_id'];
//
//        $Wxpay->updata_card_infos($updata);
//        //调用充送END
//        $give_rec_id = $CardCzLog->where('orderid', $updata['orderid'])->value('id');
//        if ($give_rec_id) {
//            $ress = $CardGivecardLog->where('give_rec_id', $give_rec_id)->find();
//            if ($ress) {
//                //查询领卡记录
//                $user = $CardUserGet->where('id', $updata['get_card_id'])->field('code,card_id,id,nickname')->find();
//                $Platurl = new Platurl();
//                $agent_url = $Platurl->getagenturl('card_id', $user['card_id']);
//                $url = $agent_url . '/mobile.php?s=/cardget/getcards/mid/' . $updata['mid'] . '/rec_id/' . $give_rec_id;
//            } else {
//                $url = 0;
//            }
//        }else{
//            $url = 0;
//        }
//        var_dump($url);
//        exit();
////        } catch (\Exception $e) {
////            $res = json_encode(array('code' => '9099', 'message' => $e->getMessage()));
////            $url = 0;
////        }
//        var_dump($url);
//        exit();
//        file_put_contents('/data2/html/payos/chackputurl.txt', 'syn-e:' . json_encode($res).PHP_EOL, FILE_APPEND);
//        return $url;
//    }
//
//
//    public function jcorder(){
//        $Merchant = new Merchant();
//        $Agent = new Agent();
//        $WxOpen = new WxOpen();
//        $map['id'] = '720';
//        $config = $Merchant->where($map)->find();
//        $agent = $Agent->where(array('id' => $config['agent']))->find();
//        $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
//        $userwx = $WxOpen->where(array('id' => $config['wx_open_id']))->find();
//        $options = array(
//            'appid' => $users['authorizer_appid'], // 填写高级调用功能的app id
//            'partnerid' => $agent['partnerid'], // 财付通商户身份标识
//            'partnerkey' => $agent['partnerkey'], // 财付通商户权限密钥Key
//        );
//        $weObj = new Wxobjopen($options);
//        $appid = $users['authorizer_appid'];
//        $mch_id = $agent['partnerid'];
//        $out_trade_no = 'H720-20181202132610158906';
//        $nonce_str = $weObj->generateNonceStr();
//        $sub_mch_id = $config['sub_mch_id'];
//        $sub_appid = $userwx['authorizer_appid'];
//        $pay_xml = $weObj->createOrderXml($appid, $mch_id, $sub_appid, $sub_mch_id, $out_trade_no, $nonce_str);
//        $payorder_xml = $weObj->getPayNum($pay_xml);
//        var_dump($payorder_xml);
//    }
//
//    public function getcard(){
//        $param['merchantid'] = '501';
//        $param['start_time'] = '2018/11/1 0:0:0';
//        $param['end_time'] = '2018/11/30 0:0:0';
//        $res = $this->cardstatis($param);
//        return json($res);
//    }
//
//
//    //会员卡消费充值统计
//    public function cardstatis($param)
//    {
//        try {
//            $CardUserGet = new CardUserGet();
//            $CardUserFee = new CardUserFee();
//            $CardUserBonus = new CardUserBonus();
//            $map['mid'] = $param['merchantid'];
//            $start_time = strtotime($param['start_time']);
//            $end_time = strtotime($param['end_time']);
//            $mae['mid'] = $param['merchantid'];
//            if ($start_time == "" && $end_time == "") {
//                $map['create_time'] = array(array('egt', 0), array('elt', time()), 'and');
//            } elseif ($start_time !== "" && $end_time == "") {
//                $map['create_time'] = array(array('egt', $start_time), array('elt', $end_time), 'and');
//            } elseif ($start_time == "" && $end_time !== "") {
//                $map['create_time'] = array(array('egt', 0), array('elt', $end_time));
//            } else {
//                $map['create_time'] = array(array('egt', $start_time), array('elt', $end_time));
//            }
//            $re_data['add_member'] = $CardUserGet->where($map)->where(['have' => 1, 'fire' => 1,'card_type'=>'MEMBER_CARD'])->count();//新增会员
//            var_dump($CardUserGet->getLastSql());
//            $re_data['rec_fee'] = number_format($CardUserFee->where($map)->where(['type' => 1])->sum('num'), 2);//充值到账金额
//            $re_data['rec_bonus'] = number_format($CardUserBonus->where(['type' => 1])->where($map)->sum('num'), 2);//新增积分
//            $re_data['ret_bonus'] = number_format($CardUserBonus->where(['type' => 2])->where($map)->sum('num'), 2);//消费积分
//
//            $recs = $CardUserFee->where($map)->where(['type' => 1, 'cate' => 1])->field('count(id) as rec_order,sum(num) as rec_ought_fee')->find();
//            $re_data['rec_order'] = number_format($recs['rec_order'], 2);//充值笔数
//            $re_data['rec_ought_fee'] = number_format($recs['rec_ought_fee'], 2);//实充金额
//            $recs2 = $CardUserFee->where($map)->where(['type' => 1, 'cate' => ['neq', 1]])->field('sum(num) as rec_give_fee')->find();
//            $re_data['rec_give_fee'] = number_format($recs2['rec_give_fee'], 2);//赠送金额
//            //渠道统计
//            //微信
//            $wx_c = $CardUserFee->where($map)->where(['type' => 1, 'cate' => 1, 'pay_cate' => 2])->field('count(id) as rec_order,sum(num) as rec_ought_fee')->find();
//            $wx_z = $CardUserFee->where($map)->where(['type' => 1, 'cate' => ['neq', 1], 'pay_cate' => 2])->field('sum(num) as rec_give_fee')->find();
//            //支付宝
//            $ali_c = $CardUserFee->where($map)->where(['type' => 1, 'cate' => 1, 'pay_cate' => 3])->field('count(id) as rec_order,sum(num) as rec_ought_fee')->find();
//            $ali_z = $CardUserFee->where($map)->where(['type' => 1, 'cate' => ['neq', 1], 'pay_cate' => 3])->field('sum(num) as rec_give_fee')->find();
//            //现金
//            $cash_c = $CardUserFee->where($map)->where(['type' => 1, 'cate' => 1, 'pay_cate' => 4])->field('count(id) as rec_order,sum(num) as rec_ought_fee')->find();
//            $cash_z = $CardUserFee->where($map)->where(['type' => 1, 'cate' => ['neq', 1], 'pay_cate' => 4])->field('sum(num) as rec_give_fee')->find();
//            //微信
//            $online_c = $CardUserFee->where($map)->where(['type' => 1, 'cate' => 1, 'pay_cate' => ['in', '0,1']])->field('count(id) as rec_order,sum(num) as rec_ought_fee')->find();
//            $online_z = $CardUserFee->where($map)->where(['type' => 1, 'cate' => ['neq', 1], 'pay_cate' => ['in', '0,1']])->field('sum(num) as rec_give_fee')->find();
//
//            $re_data['wx_rec_order'] = $wx_c['rec_order'];//微信充值笔数
//            $re_data['wx_rec_ought_fee'] = number_format($wx_c['rec_ought_fee'], 2);//微信实充金额
//            $re_data['wx_rec_give_fee'] = number_format($wx_z['rec_give_fee'], 2);//微信赠送金额
//            $re_data['ali_rec_order'] = $ali_c['rec_order'];//支付宝充值笔数
//            $re_data['ali_rec_ought_fee'] = number_format($ali_c['rec_ought_fee'], 2);//支付宝实充金额
//            $re_data['ali_rec_give_fee'] = number_format($ali_z['rec_give_fee'], 2);//支付宝赠送金额
//            $re_data['cash_rec_order'] = $cash_c['rec_order'];//现金充值笔数
//            $re_data['cash_rec_ought_fee'] = number_format($cash_c['rec_ought_fee'], 2);//现金实充金额
//            $re_data['cash_rec_give_fee'] = number_format($cash_z['rec_give_fee'], 2);//现金赠送金额
//            $re_data['online_rec_order'] = $online_c['rec_order'];//自助充值笔数
//            $re_data['online_rec_ought_fee'] = number_format($online_c['rec_ought_fee'], 2);//自助实充金额
//            $re_data['online_rec_give_fee'] = number_format($online_z['rec_give_fee'], 2);//自助赠送金额
//            $rarr['return_code'] = "SUCCESS";
//            $rarr['return_msg'] = "";
//            $rarr['result_code'] = 'SUCCESS';
//            $rarr['result_msg'] = "获取成功";
//            $rarr['info'] = $re_data;
//        } catch (\Exception $e) {
//            $rarr['return_code'] = "FAIL";
//            $rarr['return_msg'] = "系统错误" . $e->getMessage();
//            $rarr['result_code'] = 'FAIL';
//            $rarr['result_msg'] = "系统错误" . $e->getMessage();
//        }
//        return $rarr;
//
//
//    }
//
//    public function testsqls(){
//        $condition = "b.num >0 and b.cate=2 and a.have=1 and a.fire=1 and a.card_type='MEMBER_CARD'";
//        $sql = "select count(DISTINCT b.openid) from wn_card_user_get as a LEFT JOIN wn_card_user_log as b on a.openid=b.openid where " . $condition;
//        $z = Db::query($sql);
//        halt($z);
//        if(isset($z[0]["count(DISTINCT b.openid)"])){
//            $z=$z[0]["count(DISTINCT b.openid)"];
//        }else{
//            $z=0;
//        }
//    }
//
//
//    public function cardopen(){
//        $CardMember = new CardMember();
//        $map['card_id'] = ['neq',''];
//        $Parlurl = new Platurl();
//        $cardlist = $CardMember->where($map)->field('card_id,title,brand_name')->select();
//        foreach ($cardlist as $k=>$v){
//            $url = $Parlurl->getagenturl('card_id',$v['card_id']);
//            if (strlen($url) > 12) {
//                $data[$k]['card_url'] = $url . '/mobile.php?s=/carduser/opencard/card_id/' . $v['card_id'];
//                $data[$k]['title'] = $v['title'];
//                $data[$k]['brand_name'] = $v['brand_name'];
//            }
//        }
//        return var_dump($data);
//    }
//
//    //更新付费券时间
//    public function updatepaycard(){
//        $CardPaycard = new CardPaycard();
//        $list = $CardPaycard->field('id,starttime,endtime')->select();
//        foreach ($list as $k=>$v){
//            $data[$k]['id'] = $v['id'];
//            $data[$k]['times'] = date('Y-m-d h:i:s',$v['starttime']).' - '.date('Y-m-d h:i:s',$v['endtime']);
//        }
//        $res = $CardPaycard->saveAll($data);
//        return var_dump($res);
//    }
//
//    public function updatefreecard(){
//        $CardPaycard = new CardFreecard();
//        $list = $CardPaycard->field('id,starttime,endtime')->select();
//        foreach ($list as $k=>$v){
//            $data[$k]['id'] = $v['id'];
//            $data[$k]['times'] = date('Y-m-d h:i:s',$v['starttime']).' - '.date('Y-m-d h:i:s',$v['endtime']);
//        }
////        return json($data);
//        $res = $CardPaycard->saveAll($data);
//        return var_dump($res);
//    }
//
//    public function getydhtoken(){
//        $Ydhmork = new Ydhwork();
////        $data['mid'] = 501;
////        $data['openid'] = 'oCVCLvwkYgBzdu1LLaYw5RFPngTs';
////
////        $data['c_id'] = '286';
////        $data['us_id'] = '332803';
////        $data['create_time'] = time();
//
//        $data['top_mid'] = 1;
//        $res = $Ydhmork->get_access_token(183);
//        var_dump($res);
//        exit();
//        //END
//        $data['code'] = '616796112115';
//        $data['name'] = '逆光，奔跑';
//        $data['contactor'] = '逆光，奔跑';
//        $data['mobile'] = '15836370080';
//        $data['userName'] = 'alcesh001';
//        $data['password'] = '321321';
//        $data['customertypeId'] = 2140175;
//        $data['activeCustomer'] = 1;
//        $token = $Ydhmork->create_user($data);
//        return json($token);
//        r ($token);
//    }
//
//    public function qweqweqwe(){
//        $Paylog = new Paylog();
//        $info = $Paylog->where(['id'=>'159996'])->field('orderid,openid')->find()->toArray();
////        halt($info);
//        $wxpay = new \app\index\controller\Wxpay();
//        $res = $wxpay->upgradeuser($info);
//        var_dump($res);
//
//    }
//
//    public function user_lists(){
//        $data['top_mid'] = 1;
//        $data['customertypeId'] = 2140175;
//        $data['name'] = 'www';
////        $data['beginTime'] = '2018-10-14';
////        $data['endTime'] = '2018-10-16';
////        $data['listType'] = 'page';
//        $Ydhmork = new Ydhwork();
//        $token = $Ydhmork->user_list($data);
//        return json($token);
//    }
//
//    public function editydhtoken(){
//        $Ydhmork = new Ydhwork();
////        $data['mid'] = 501;
////        $data['openid'] = 'oCVCLvwkYgBzdu1LLaYw5RFPngTs';
////
////        $data['c_id'] = '286';
////        $data['us_id'] = '332803';                62914145
////        $data['create_time'] = time();
//
//        $data['top_mid'] = 1;
//        //END
//        $data['id'] = 62924106;
//        $data['code'] = '047622123661';
//        $data['name'] = '逆光，奔跑';
//        $data['contactor'] = '逆光，奔跑';
//        $data['mobile'] = '15836370080';
////        $data['userName'] = 'alcesh001';
////        $data['password'] = '321321';
//        $data['customertypeId'] = 4315587;
//        $data['activeCustomer'] = 1;
//        $token = $Ydhmork->update_user($data);
//        return json($token);
//        r ($token);
//    }
//
//    public function ydhinfo(){
//        $Ydhmork = new Ydhwork();
//        $data['top_mid'] = 1;
//        $data['id'] = 62914145;
//        $data['code'] = 047622123661;
//        $data['loadrReceive'] = false;
//        $token = $Ydhmork->ydhinfo($data);
//        return json($token);
//    }
//
    public function getydhcate(){

        $top_mid = 183;
//        $YdhOpen = new YdhOpen();
//        $time = time();
//        $map['top_mid'] = $top_mid;
//        $openinfo = $YdhOpen->where($map)->find();
//        $expires_time = $openinfo['expires_in'] + $openinfo['expires_time']-1728000;
//        var_dump($expires_time);
//        exit();
//        if ($time > $expires_time) {
//
//        }



        $YdhWork = new Ydhwork();
        $token = $YdhWork->get_user_cate($top_mid);
//        $token = $this->get_access_token_ydh($top_mid);

//        $map['top_mid'] = 183;
//        $YdhOpen = new YdhOpen();
//        $openinfo = $YdhOpen->where($map)->find();
        return json($token);
    }
//
//    public function get_access_token_ydh($top_mid){
//
//        $YdhOpen = new YdhOpen();
//        $time = time();
//        $map['top_mid'] = $top_mid;
//        $openinfo = $YdhOpen->where($map)->find();
//        $expires_time = $openinfo['expires_in'] + $openinfo['expires_time']-600;
//
//        if ($expires_time > $time) {
//            $data = [
//                'userName' => $openinfo['username'],
//                'password' => $openinfo['password'],
//                'client_id' => $openinfo['client_id'],
//                'client_secret' => $openinfo['client_secret'],
//                'grant_type' => $openinfo['grant_type'],
//                'scope' => $openinfo['scope'],
//            ];
//            $url = 'https://api.dinghuo123.com/v2/oauth2/token?';
//            $res = $this->http_get($url.http_build_query($data));
//            $res = json_decode($res,true);
//            if ($res['code'] == 200) {
//                $datas['access_token'] = $res['data']['access_token'];
//                $datas['create_time'] = time();
//                $datas['expires_in'] = $res['data']['expires_in'];
//                $ress = $YdhOpen->allowField(true)->save($datas,$map);
//
//                if ($ress){
//                    $accesstoken = $datas['access_token'];
//                }else{
//                    $accesstoken = $datas['access_token'];
//                }
//            }else{
//                $accesstoken = $openinfo['access_token'];
//            }
//        }else{
//            $accesstoken = $openinfo['access_token'];
//        }
//        return $accesstoken;
//    }
//
//    public function mch_pay_statis()
//    {
//        $MchStatis = new MchStatis();
//        $infos2 = [];
//        $wxpay = [];
//        $alipay = [];
//        $cashpay = [];
//        $wxcardpay = [];
//        $othercount = [];
//        $other2 = [];
//        $start_time = strtotime('2018-10-10') - 86400;
//        $end_time = $start_time + 86399;
//        $statisinfo = $MchStatis->where('statis_times', $start_time)->find();
//        if (!$statisinfo) {
//            $condition = "p.mid = a.id and  pay_cate <> 'recharge' and p.pay_statu <> 0 and p.pay_statu <> 8 and (p.add_time >= :start_time and p.add_time <= :end_time)";
//            $param = ['start_time' => $start_time, 'end_time' => $end_time];
////            halt($param);
//            //微信支付统计 带手续费
//            $condition_1 = $condition . "  and p.pay_fs in (0,2)";
//            $field = 'a.id as mid,a.top_mid,a.agent,sum(p.price) as wx_fee,count(p.id) as wx_order,sum(p.service_charge) as wx_service_charge';
//            $wxpay = $this->statissql($condition_1, $param, $field);
//
//            //支付宝支付统计 带手续费
//            $condition_2 = $condition . "  and p.pay_fs in (1,3)";
//            $field = 'a.id as mid,a.top_mid,a.agent,sum(p.price) as ali_fee,count(p.id) as ali_order,sum(p.service_charge) as ali_service_charge';
//            $alipay = $this->statissql($condition_2, $param, $field);
//            //POS支付统计 带手续费
//            $condition_6 = $condition . "  and p.pay_fs = 5";
//            $field = 'a.id as mid,a.top_mid,a.agent,sum(p.price) as pos_fee,count(p.id) as pos_order,sum(p.service_charge) as pos_service_charge';
//            $pospay = $this->statissql($condition_6, $param, $field);
//
//            //现金支付统计
//            $condition_3 = $condition . "  and p.pay_fs = 4";
//            $field = 'a.id as mid,a.top_mid,a.agent,sum(p.price) as cash_fee,count(p.id) as cash_order';
//            $cashpay = $this->statissql($condition_3, $param, $field);
//            //会员卡支付统计
//            $condition_4 = $condition . "  and p.pay_fs = 8";
//            $field = 'a.id as mid,a.top_mid,a.agent,sum(p.price) as wx_card_fee,count(p.id) as wx_card_order';
//            $wxcardpay = $this->statissql($condition_4, $param, $field);
//            //折扣 应收 实收统计
//            $condition_o = $condition . " and p.pay_fs in (0,1,2,3,4,8)";
//            $field = 'a.id as mid,sum(p.zk_price) as dis_fee,a.top_mid,a.agent,sum(p.yf_price) as ought_fee,sum(p.price) as real_fee,count(p.id) as real_order,avg(p.price) as avg_fee';
//            $othercount = $this->statissql($condition_o, $param, $field);
//            //退款统计
//            $Merchant = new Merchant();
//            $other2 = $Merchant
//                ->alias('a')
//                ->join('wn_tklog t', 't.mid = a.id and t.tk_status = 1 and (t.addtime >= :start_time and t.addtime <= :end_time)', 'left')
//                ->group('a.id')
//                ->bind($param)
//                ->field('a.id as mid,a.top_mid,a.agent,sum(t.refund_fee) as refund_fee,count(t.id) as refund_order')
//                ->select();
//            $infos = array_merge($wxpay, $alipay,$pospay, $cashpay, $wxcardpay, $othercount, $other2);
//            $mchlist = array_unique(array_column($wxpay, 'mid'));
//            foreach ($mchlist as $k => $v) {
//                foreach ($infos as $ks => $vs) {
//                    if ($vs['mid'] == $v) {
//                        $infos2[$k]['mid'] = $vs['mid'];
//                        $infos2[$k]['agent'] = $vs['agent'];
//                        $infos2[$k]['top_mid'] = $vs['top_mid'];
//                        $infos2[$k]['create_time'] = time();
//                        $infos2[$k]['statis_time'] = date('Y-m-d H:i:s', $start_time);
//                        $infos2[$k]['statis_times'] = $start_time;
//                        $infos2[$k]['statis_action'] = 1;
//                        if (isset($vs['wx_order'])) {
//                            $infos2[$k]['wx_fee'] = !empty($vs['wx_fee']) ? $vs['wx_fee'] : 0.00;
//                            $infos2[$k]['wx_order'] = $vs['wx_order'];
//                            $infos2[$k]['wx_service_charge'] = !empty($vs['wx_service_charge']) ? $vs['wx_service_charge'] : 0.00;
//                        }
//                        if (isset($vs['real_order'])) {
//                            $infos2[$k]['dis_fee'] = !empty($vs['dis_fee']) ? $vs['dis_fee'] : 0.00;
//                            $infos2[$k]['ought_fee'] = !empty($vs['ought_fee']) ? $vs['ought_fee'] : 0.00;
//                            $infos2[$k]['avg_fee'] = !empty($vs['avg_fee']) ? $vs['avg_fee'] : 0.00;
//                            $infos2[$k]['real_fee'] = !empty($vs['real_fee']) ? $vs['real_fee'] : 0.00;
//                            $infos2[$k]['real_order'] = !empty($vs['real_order']) ? $vs['real_order'] : 0;
//                        }
//                        if (isset($vs['ali_order'])) {
//                            $infos2[$k]['ali_fee'] = !empty($vs['ali_fee']) ? $vs['ali_fee'] : 0.00;
//                            $infos2[$k]['ali_order'] = $vs['ali_order'];
//                            $infos2[$k]['ali_service_charge'] = !empty($vs['ali_service_charge']) ? $vs['ali_service_charge'] : 0.00;
//                        }
//                        if (isset($vs['pos_order'])) {
//                            $infos2[$k]['pos_fee'] = !empty($vs['pos_fee']) ? $vs['pos_fee'] : 0.00;
//                            $infos2[$k]['pos_order'] = $vs['pos_order'];
//                            $infos2[$k]['pos_service_charge'] = !empty($vs['pos_service_charge']) ? $vs['pos_service_charge'] : 0.00;
//                        }
//                        if (isset($vs['cash_order'])) {
//                            $infos2[$k]['cash_fee'] = !empty($vs['cash_fee']) ? $vs['cash_fee'] : 0.00;
//                            $infos2[$k]['cash_order'] = $vs['cash_order'];
//                        }
//                        if (isset($vs['wx_card_order'])) {
//                            $infos2[$k]['wx_card_fee'] = !empty($vs['wx_card_fee']) ? $vs['wx_card_fee'] : 0.00;
//                            $infos2[$k]['wx_card_order'] = $vs['wx_card_order'];
//                        }
//                        if (isset($vs['refund_order'])) {
//                            $infos2[$k]['refund_fee'] = !empty($vs['refund_fee']) ? $vs['refund_fee'] : 0.00;
//                            $infos2[$k]['refund_order'] = $vs['refund_order'];
//                        }
//                    }
//                }
//            }
//            return json($infos2);
//            $MchStatis = new MchStatis();
//            $MchStatis->saveAll($infos2);
//        }
//
//    }
//
//    //
//    public function userfee(){
//        $arr['mid'] = '722';
//        $arr['top_mid'] = '151';
//        $arr['card_id'] = 'pePs8v3mm3nHv2YmOVceVeLllNvI';
//        $arr['rec_id'] = '4285';
//        $arr['c_id'] = 248;
//        $arr['orderid'] = 'H722-2018101212313694628';
//        $arr['oid'] = 154880;
//        $arr['us_id'] = 297017;
//        $arr['openid'] = 'oePs8v2jA__Y1uvXSCylgsXlHe3Q';
//        $arr['code'] = 135701869905;
//        $arr['num'] = 300;
//        $arr['pay_cate'] = 0;
//        $arr['mode'] = 0;//数据写入方式兼容
//        $arr['type'] = 1; //1增加 2减少
//        $arr['cate'] = 1;
//        $arr['source'] = 'online'; //来源
//        $arr['remark'] = '充值';  //备注
//        $arr['action_user'] = '美丽无声';
//        $arr['act_source'] = 1;
//        $arr['create_time'] = 1539318707;
//        $Balance = new CardUserFee();
//        $Balance->save($arr);
//
////        $arrs['rec_id'] = 4277;
////        $arrs['card_id'] = 'pePs8v3mm3nHv2YmOVceVeLllNvI';
////        $arrs['code'] = '135701869905';
////        $arrs['username'] = '美丽无声';
////        $arrs['giveid'] = '';
////        $arrs['orderid'] = 'H722-2018101212090168097';
////        $arrs['add_balance'] = 10;
////        $Wxpay = new \app\index\controller\Wxpay();
////        $res = $Wxpay->cz_bonus_fee($arrs);
////        var_dump($res);
//
//    }
//
//    private function statissql($condition, $param, $field)
//    {
//        $Merchant = new Merchant();
//        $sql = $Merchant
//            ->alias('a')
//            ->join('wn_paylog p', $condition, "LEFT")
//            ->group('a.id')
//            ->bind($param)
//            ->field($field)
//            ->select();
//
////        return $sql;
//
//        return collection($sql)->toArray();
//
//    }
//
//    public function tests(){
//        $CardUserGet=new CardUserGet();
//        $data['code']="894567204511";
////     $CardUserGet->create($data);
//        $result = $CardUserGet->validate([
//            'code'  => 'require|unique:CardUserGet'])->save($data);
//    }
//
//    public function testfiress(){
//        $CardUserGet = new CardUserGet();
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['fire'] = 1;
//        $map['create_time'] = [['GT',1535968800],['LT',1535979600]];
//        $list = $CardUserGet->where($map)->field('card_id,code,id')->select();
//        $unm = $CardUserGet->where($map)->count('id');
////        var_dump($CardUserGet->getLastSql());
////        exit();
////        var_dump($unm);
////        return json($list);
//        foreach ($list as $k=>$v){
//            $open = $this->options($v['card_id']);
//            $wxObj = new Wxobjopen($open);
//            $datas['card_id'] = $v['card_id'];
//            $datas['code'] = $v['code'];
//            $res = $wxObj->userGetInfo($datas);
////            var_dump($res);
//            if ($res['errcode'] == 0){
//                if ($res['has_active'] == false){
////                    $data['fire'] = 0;
////                    $ress = $CardUserGet->save($data,['id'=>$v['id']]);
//                    var_dump($res);
//                }
//            }
//        }
//    }
//
//    //更新会员卡状态为结束跟随推荐
//    public function endcardus(){
//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $datas['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $datas['member_card']['modify_msg_operation']['url_cell']['card_id_list'] = [];
//        $datas['member_card']['modify_msg_operation']['url_cell']['end_time'] = time();
//        $datas['member_card']['modify_msg_operation']['url_cell']['text'] = '';
//        $datas['member_card']['modify_msg_operation']['url_cell']['url'] = '';
//        $option = $this->options($card_id);
//        $WxObj = new Wxobjopen($option);
//        $res = $WxObj->updateUserCard($datas);
//        print_r($res);
////        $ActionLogs = new ActionLogs();
////        $ActionLogs-> writelog("payos","sendbiz","send/bizend","关闭跟随推荐:",$res);
//    }
//
//    public function paybonus($orderid ='H501-20180703172755592976'){
//        $Paylog = new Paylog();
//        $payinfo = $Paylog->where(array('orderid'=>$orderid))->field('orderid,mid,pay_cate,openid,sub_openid,price,yf_price,pay_fs,d_cashier')->find();
//        $res = $this->pay_inc_bonus($payinfo);
//        var_dump($res);
//
//    }
//
//
//
//    public function testarr(){
//        $cardlist = '[{"zs_card_id":"pCVCLvzVusuLW4WPU4xjDCvA8Cnk","zs_no":"2"},
//    {"zs_card_id":"pCVCLv3qLv7aRubXzvHbC0-TWOmA","zs_no":"1"},
//    {"zs_card_id":"pCVCLvyNYJLs6DlUUySGvMCTp_Qs","zs_no":"1"},
//    {"zs_card_id":"pCVCLv2SLNUZ1jMNiGGKht12VAJY","zs_no":"1"},
//    {"zs_card_id":"pCVCLv0qOFPK4qu2eqzNRaKOmGP8","zs_no":"1"},
//    {"zs_card_id":"pCVCLv8rbrqMlFRKpdAI1Kg6O5HQ","zs_no":"1"},
//    {"zs_card_id":"pCVCLv8z_rEg1gdVoMQequfMDd4c","zs_no":"1"},
//    {"zs_card_id":"pCVCLv8UyHl7WUhqSIvj4i3s5uO8","zs_no":"1"},
//    {"zs_card_id":"pCVCLv0TSm0ZDdbO2bhMI1tBxcxs","zs_no":"1"},
//    {"zs_card_id":"pCVCLv1QLIU_FJhOB9O9e_or2Rlc","zs_no":"1"},
//    {"zs_card_id":"pCVCLv4236z38Fck2v6F5ZPaLTdI","zs_no":"1"},
//    {"zs_card_id":"pCVCLv7q8nN3P4BHns4jqCKvjVNE","zs_no":"1"}]';
//        $cardlist = json_decode($cardlist, true);
////        $zs_card_id = implode(",", array_column($cardlist, 'zs_card_id'));
//        $sinfo = array_search('1', $cardlist);
//        halt($sinfo);
////        return $sinfo;
//    }
//
//    public function balance(Request $request){
////        Debug::remark('begin');
//        $CardUserUpdate = new CardUserUpdate();
//        $param = $request->param();
////        return json($param);
//        $map['create_time'] = ['gt',1535731200];
////        $list = $CardUserUpdate->alias('a')->where($map)
////            ->join('paylog b','a.orderid = b.orderid')
////            ->join('merchant c','a.mid = c.id')
////            ->join('card_member d','a.card_id = d.card_id')
////            ->join('card_user_get e','a.openid = e.openid')
////
////            ->field('a.id as uid,a.top_mid,a.mid,a.create_time,a.openid,a.code,a.card_id,a.orderid,a.reason,a.hx_fs,a.type,a.source,a.record_balance,a.add_balance as num,a.pay_balance as pay_num,a.add_balance-a.pay_balance as zs_num
////            ,b.orderid,b.id as oid,c.top_mid,c.id as top_mid,d.card_id,d.id as c_id,e.openid,e.id as us_c_id
////            ')->limit(10)->select();
////        return json($CardUserUpdate->getLastSql());
//
////        Debug::remark('end');
//        $map['add_balance|del_balance|pay_balance'] = ['gt',0];
//        $list = $CardUserUpdate->where($map)->field('mid,openid,code,card_id,source,record_balance,reason,orderid,add_balance as add_num,pay_balance as pay_num,add_balance-pay_balance as zs_num')->limit(10)->select();
////        return json($CardUserUpdate->getLastSql());
//        return json($list);
////       var_dump($list);
////        echo Debug::getRangeTime('begin','end').'s';
////        return json($list);
////        var_dump(collection($list)->toArray());
//        $Merchant = new  Merchant();
//        $Paylog = new Paylog();
//        $CardMember = new CardMember();
//        $CardUserGet = new CardUserGet();
//        $i = 0;
//        $time = time();
//        foreach ($list as $k=>$v){
//            $top_mid = $Merchant->where('id',$v['mid'])->value('top_mid');
//            $oid = $Paylog->where('orderid',$v['orderid'])->value('id');
//            $c_id = $CardMember->where('card_id',$v['card_id'])->value('id');
//            $us_id = $CardUserGet->where(['card_id'=>$v['mid'],['code'=>$v['code']]])->value('id');
//            $data[$i]['top_mid'] = $top_mid;
//            $data[$i]['mid'] = $v['mid'];
//            $data[$i]['openid'] = $v['openid'];
//            $data[$i]['code'] = $v['code'];
//            $data[$i]['card_id'] = $v['card_id'];
//            $data[$i]['c_id'] = $c_id;
//            $data[$i]['us_id'] = $us_id;
//            $data[$i]['orderid'] = $oid;
//            $data[$i]['type'] = 1;
//            $data[$i]['cate'] = 10;
//            $data[$i]['source'] = $v['source'];
//            $data[$i]['remark'] = $v['record_balance'];
//            $data[$i]['num'] = $v['pay_num'];
//            $data[$i]['create_time'] = $v['create_time'];
//            $i = $i+1;
//            //增送
//            if ($v['zs_num'] > 0){
//                $data[$i]['top_mid'] = $v['top_mid'];
//                $data[$i]['mid'] = $v['mid'];
//                $data[$i]['openid'] = $v['openid'];
//                $data[$i]['code'] = $v['code'];
//                $data[$i]['card_id'] = $v['card_id'];
//                $data[$i]['orderid'] = $v['orderid'];
//                $data[$i]['type'] = 1;
//                $data[$i]['cate'] = $v['hx_fs'] ==8?'9':$this->getcate($v['reason']);   //消费  /  核销
//                $data[$i]['source'] = $v['source'];
//                $data[$i]['remark'] = $v['record_balance'];
//                $data[$i]['num'] = $v['zs_num'];
//                $data[$i]['create_time'] = $v['create_time'];
//                $i = $i +1;
//            }
//            var_dump($i);
//        }
//        $CardUserFee = new CardUserFee();
//        $CardUserFee->allowField(true)->saveAll($data);
//        return json($CardUserFee->getLastSql());
//    }
//
//    //余额转换
//    public function rec_balance_fee(Request $request){
//        $CardUserUpdate = new CardUserUpdate();
//        $param = $request->param();
//
//        $map['create_time'] = ['gt',1535731200];
//        $map['id'] = ['lt',75055];
//        $map['add_balance|pay_balance'] = ['gt',0];
//        $list = $CardUserUpdate->where($map)->field('mid,openid,hx_fs,code,card_id,source,record_balance,con_username,reason,orderid,add_balance as add_num,
//        pay_balance as pay_num,add_balance-pay_balance as zs_num')->limit($param['ks'],$param['end'])->select();
////        return json($list);
//        $Merchant = new  Merchant();
//        $Paylog = new Paylog();
//        $CardMember = new CardMember();
//        $CardUserGet = new CardUserGet();
//        $i = 0;
//
//        foreach ($list as $k=>$v){
//
//            $top_mid = $Merchant->where('id',$v['mid'])->value('top_mid');
//            $oid = $Paylog->where('orderid',$v['orderid'])->value('id');
//            $c_id = $CardMember->where('card_id',$v['card_id'])->value('id');
//            $us_id = $CardUserGet->where(['card_id'=>$v['card_id'],'code'=>$v['code']])->value('id');
//            var_dump(json_encode($i));
//            $data[$i]['mid'] = $v['mid'];
//            $data[$i]['top_mid'] = $top_mid;
//            $data[$i]['card_id'] = $v['card_id'];
//            $data[$i]['c_id'] = $c_id;
//            $data[$i]['us_id'] = $us_id;
//            $data[$i]['openid'] = $v['openid'];
//            $data[$i]['code'] = $v['code'];
//            $data[$i]['orderid'] = $v['orderid'];
//            $data[$i]['oid'] = $oid;
//            $data[$i]['num'] = $v['pay_num'];
//            $data[$i]['pay_cate'] = $v['hx_fs'];
//            $data[$i]['type'] = 1;
//            $data[$i]['cate'] = 1;
//            $data[$i]['source'] = $v['source'];
//            $data[$i]['remark'] = $v['record_balance'];
//            $data[$i]['action_user'] = $v['con_username'];
//            $data[$i]['create_time'] = $v['create_time'];
//            $i = $i+1;
//
//            //增送
//            if ($v['zs_num'] > 0){
//                $data[$i]['mid'] = $v['mid'];
//                $data[$i]['top_mid'] = $top_mid;
//                $data[$i]['card_id'] = $v['card_id'];
//                $data[$i]['c_id'] = $c_id;
//                $data[$i]['us_id'] = $us_id;
//                $data[$i]['openid'] = $v['openid'];
//                $data[$i]['code'] = $v['code'];
//                $data[$i]['orderid'] = $v['orderid'];
//                $data[$i]['oid'] = $oid;
//                $data[$i]['num'] = $v['pay_num'];
//                $data[$i]['pay_cate'] = $v['hx_fs'];
//                $data[$i]['type'] = 1;
//                $data[$i]['cate'] = 1;
//                $data[$i]['source'] = $v['source'];
//                $data[$i]['remark'] = $v['record_balance'];
//                $data[$i]['action_user'] = $v['con_username'];
//                $data[$i]['create_time'] = $v['create_time'];
//                $i = $i +1;
//            }
//            var_dump($i);
//        }
//        return json($data);
//    }
//
//
//    //测试等级类
    public function testrank(){
        Debug::remark('begin');
// ...其他代码段

//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $code = '819240230226';
//        $bonus = '22';
//        $Level = new Leveltest();
//        $res = $Level->checklevel($card_id,$code,$bonus);
//        var_dump($res);
        $data['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
        $data['code'] = '819240230226';
        $data['level'] = '黄金会员';
        $data['background_pic_url'] = '';
        $res = $this->updatelevel($data);
        var_dump($res);
        Debug::remark('end');
        echo Debug::getRangeTime('begin','end').'s';
    }
//
    public function updatelevel($arr)
    {
        try {
            //实例化微信
            $options = $this->options($arr['card_id']);
            $WxObj = new Wxobjopen($options);
            $data = [
                'code' => $arr['code'],
                'card_id' => $arr['card_id'],
                'custom_field_value3' => $arr['level'],
                'notify_optional' => [
                    'is_notify_bonus' => false,
                    'is_notify_balance' => false,
                    'is_notify_custom_field1' => false,
                ],
            ];
            $data['background_pic_url'] = $arr['background_pic_url'];
//            if (!empty($arr['background_pic_url'])) {
//
//            }
            $res = $WxObj->updateUserInfo($data);
        } catch (\Exception $e) {
            $res = ['errcode' => 9999, 'message' => $e->getMessage()];
        }
        return $res;
    }



    //
    public function updatalevel(){
        $data['card_id'] = "pQUjL5nRGAmG2fIdp-_3_M5bbv50";
        $data['openid'] = "oQUjL5izR3b48eJnfciqF5aasw0E";
        $res = $this->getfirecard($data);
        var_dump($res);
    }

    public function getfirecard($param)
    {
        $CardGive = new CardGive();
        $CardUserGet = new CardUserGet();
        $giveinfo = $CardGive->where(['card_id' => $param['card_id'], 'statu' => 1])->find();
        //END
        $Momerchant = new Momerchant();
        $sinfo = $Momerchant->where('id', $giveinfo['top_mid'])->value('wx_open_id');
        $WxOpen = new WxOpen();
        $sappid = $WxOpen->where('id', $sinfo)->value('authorizer_appid');
        $openid = Session::get($sappid . '_openid');
        if(!$openid){
            $openid=$param['openid'];
        }
        //END
        $user = $CardUserGet->where(['card_id' => $giveinfo['card_id'], 'openid' => $openid])->field('c_id,id,fire,top_mid,mid,code,card_id,openid')->find();

        if ($user['fire'] == "1" || $user['fire'] == 1) {
            if ($giveinfo) {
                if ($giveinfo['end_time'] > time()) {
                    if ($giveinfo['card_no'] > 0) {
                        $data['card_id_list'] = $giveinfo['card_id_list'];
                        $data['give_id'] = $giveinfo['id'];
                        $CardGivePutCard = new CardGivePutCard();
                        $data['top_mid'] = $user['top_mid'];
                        $data['us_c_id'] = $user['id'];
                        $data['c_id'] = $user['c_id'];
                        $data['mid'] = $user['mid'];
                        $data['code'] = $user['code'];
                        $data['card_id'] = $user['card_id'];
                        $data['openid'] = $user['openid'];
                        $data['give_type'] = 'fire_card';
                        $data['give_id'] = $giveinfo['id'];
                        $data['create_time'] = time();
                        $CardGivePutCard->allowField(true)->save($data);
                        $data['give_rec_id'] = $CardGivePutCard->id;
                        $res = $this->get_fire_cardslog($data);
                        $resut['card'] = $res;
                        $datac['giveinfo'] = json_encode($resut, JSON_UNESCAPED_UNICODE);
                        $CardGivePutCard->allowField(true)->save($datac, ['id' => $data['give_rec_id']]);
                        //END
//                        $Platurl = new Platurl();
//                        $agent_url = $Platurl->getagenturl('card_id',$user['card_id']);
                        $resut['give_rec_id'] = $data['give_rec_id'];
                        $resut['code'] = 1;
                        $resut['card'] = '赠送成功';
                    } else {
                        $resut['code'] = 2;
                        $resut['card'] = '无券赠送1';
                    }
                } else {
                    $resut['code'] = 3;
                    $resut['card'] = '已结束';
                }
            } else {
                $resut['code'] = 4;
                $resut['card'] = '无券赠送2';
            }
        } else {
            $resut['code'] = 5;
            $resut['card'] = '未激活';
        }
        return $resut;
    }

    public function get_fire_cardslog($arr)
    {
        $CardGivecardLog = new CardGivecardLog();
        $zs_card_id = $arr['card_id_list'];
        if ($zs_card_id) {
            $zs_card_id = json_decode($zs_card_id,true);
            $datass['cardlist'] = $zs_card_id;
            $WnObj = new WnObj($datass);
            $arrs = $WnObj->isgetputsume_rec();
            $data = [];
            if (!empty($arrs)) {
                $CardUserGet = new CardUserGet();
                $user = $CardUserGet->where(array('openid'=>$arr['openid'],'card_id'=>$arr['card_id']))->field('id,c_id')->find();
                foreach ($arrs as $k => $v) {
                    $data[$k]['card_id'] = $arr['card_id'];
                    $data[$k]['openid'] = $arr['openid'];
                    $data[$k]['us_c_id'] = $user['id'];
                    $data[$k]['c_id'] = $user['c_id'];
                    $data[$k]['code'] = $arr['code'];
                    $data[$k]['zs_card_id'] = $v['card_id'];
                    $data[$k]['give_rec_id'] = $arr['give_rec_id'];
                    $data[$k]['mid'] = $arr['mid'];
                    $data[$k]['top_mid'] = $arr['top_mid'];
                    $data[$k]['put_sume'] = $v['zs_no'];
                    $data[$k]['put_type'] = 'fire_card';
                    $data[$k]['create_time'] = time();
                }
            }



//            if (isset($data)) {
            $res = $CardGivecardLog->allowField(true)->saveAll($data);
//            }
        } else {
            $res = 'no card send';
        }
        return $res;
    }


    public function testbonus(){
        $res =  [
            "card_id"=> "pCVCLv813IF--MsBtSm80ehRjoco",
            "code"=>  "762073545911",
            "num"=>  "10",
            "remark"=>  "分享有礼",
            "type"=>  1,
            "cate"=>  7,
            "pay_cate"=>  24,
            "source"=>  "online",
            "orderid"=>  "",
            "action_user"=>  "SHAREGIFT",
            "bd_cate"=>  "bonus"
        ];
        $WNobj = new WnCardObj($res);
        $ress = $WNobj->init();
        var_dump($ress);
    }
//
//    public function pageinfo(){
//        $options = $this->options('pDsgV1pHhqyZ0Ne2kXYkMF0r4XqY');
//        $WxObj = new Wxobjopen($options);
//        $data['page_id'] = 'cIUbkbRSmEB1Q8g+hdVGPk3ESju5GcJeFnitBGfZXfc=';
//        $res = $WxObj->getGiftPage($data);
//        var_dump($res);
//    }
//
//    public function getcate($id){
//        switch ($id){
//            case "1";
//                $r = '2';
//                break;
//            case "2";
//                $r = '1';
//                break;
//            case "3";
//                $r = '10';
//                break;
//            case "4";
//                $r = '3';
//                break;
//            case "5";
//                $r = '4';
//                break;
//            case "6";
//                $r = '6';
//                break;
//            case "7";
//                $r = '5';
//                break;
//            case "19";
//                $r = '8';
//                break;
//            case "11";
//                $r = '7';
//                break;
//        }
//        return $r;
//    }
//
//    //获取卡券核销状态
//    public function getcardstaturl(){
//        $data['card_id'] = 'pCVCLv4236z38Fck2v6F5ZPaLTdI';
//        $data['code'] = '213141990831';
//        $url = 'https://api.weixin.qq.com/card/code/get?access_token=';
//        $acc = '13_xaB50fLrjlY7HnTD_9Vrae1cMUPgrhufMrjadXcbX3QpnMggSO7THYCYjpmJ2NJNsNE3ocMQkxx-5y4mVcr3I9GwfCAIUewobJ2YQ1diEG7aiSKZnYncGrGUNvsVgTwFKhIQv-7FbgRZ09bCEDSjAMDQPE';
//        $res = $this->http_post($url . $acc, json_encode($data, JSON_UNESCAPED_UNICODE));
//        return json($res);
//    }
//
//    //九月1日前积分
//
//    //获取
//    public function gettpllist(){
//        $wxOpen = new WxOpen();
//        $AccessToken = $wxOpen->where(['id'=>19])->value('at_access_token');
//        $acc = '13__btYn50rDhxzhUwZpOgr6g1HiFjaV4U1AmWabcX_7CkhNuiiXf4YEe90FOmH6Svi8_cGEFD2e92Ef-izyjdV186zlPmegd778a1UQBZ03loJNnXQMao6aBptads3fAsfk2A4TJJD9LzEIfmyOKQbAGDYUA';
//        $url = 'https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=';
//        $res = $this->http_get($url . $AccessToken);
//        return json($res);
//    }
//
//    //修改跟随  积分
//    public function editcardbonus(){
//        $data['card_id'] = 'pCVCLv3pK-SMO2xosWUjdrUD06_w';
//        $data['member_card']['modify_msg_operation']['url_cell']['card_id_list'] = ['pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLvxx_1Sdt5kXsosv8d7hmeQ4','pCVCLvzxIIcpV9LgwmiBXijmk6kw'];
//        $data['member_card']['modify_msg_operation']['url_cell']['end_time'] = 1538236800;
//        $data['member_card']['modify_msg_operation']['url_cell']['text'] = '赠送您****优惠券，请注意查收';
//        $data['member_card']['modify_msg_operation']['url_cell']['url'] = 'https://os.wunengkeji.com/mobile.php?s=/cardgettest/getfirecard/card_id/'.$data['card_id'];;
//        $url = 'https://api.weixin.qq.com/card/update?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump($res);
//    }
//
//    //修改跟随  激活
//    public function editcardfire(){
//        $data['card_id'] = 'pCVCLv9m9h42EE9bSHNNqgX-VoGA';
//        $data['member_card']['activate_msg_operation']['url_cell']['card_id_list'] = ['pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLv2Aaa5sqTDMrmX5ZDSI3hs8','pCVCLvxx_1Sdt5kXsosv8d7hmeQ4','pCVCLvzxIIcpV9LgwmiBXijmk6kw'];
//        $data['member_card']['activate_msg_operation']['url_cell']['end_time'] = 1538236800;
//        $data['member_card']['activate_msg_operation']['url_cell']['text'] = '赠送您****优惠券，请注意查收';
//        $data['member_card']['activate_msg_operation']['url_cell']['url'] = 'https://os.wunengkeji.com/mobile.php?s=/cardgettest/getfirecard/momach_id/1';;
//        $url = 'https://api.weixin.qq.com/card/update?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump($res);
//    }
//
//    public function get_access_token(){
//        $YdhOpen = new YdhOpen();
//        $time = time();
//        $map['username'] = '17839197520';
//        $openinfo = $YdhOpen->where($map)->find();
////        halt($openinfo);
////        if ($openinfo['expires_in'] + $openinfo['create_time'] < $time) {
//        $data = [
//            'userName' => $openinfo['username'],
//            'password' => $openinfo['password'],
//            'client_id' => $openinfo['client_id'],
//            'client_secret' => $openinfo['client_secret'],
//            'grant_type' => 'client_credentials',
//            'scope' => 'basic',
//        ];
//        $url = 'http://api.dinghuo123.com/v2/oauth2/token/';
////            halt($data);
////            $ress = $url.http_build_query($data);
////            halt($ress);
//        $res = $this->http_get($url.http_build_query($data));
//        halt($res);
////            if ($res['code'] == 200) {
////                $datas['access_token'] = $res['data']['access_token'];
////                $datas['create_time'] = $res['data']['create_time'];
////                $datas['expires_in'] = $res['data']['expires_in'];
////                $ress = $YdhOpen->allowField(true)->save($datas,$map);
////                if ($ress){
////                    $accesstoken = $datas['access_token'];
////                }else{
////                    $accesstoken = $datas['access_token'];
////                }
////            }else{
////                $accesstoken = $openinfo['access_token'];
////            }
////        }else{
////            $accesstoken = $openinfo['access_token'];
////        }
//        return join($res);
//    }
//
////    private function http_get($url)
////    {
////        $oCurl = curl_init();
////        if (stripos($url, "https://") !== FALSE) {
////            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
////            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
////            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
////        }
////        curl_setopt($oCurl, CURLOPT_URL, $url);
////        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
////        $sContent = curl_exec($oCurl);
////        $aStatus = curl_getinfo($oCurl);
////        curl_close($oCurl);
////        if (intval($aStatus["http_code"]) == 200) {
////            return $sContent;
////        } else {
////            return false;
////        }
////    }
//
//    //送券测试
//    public function testqwe(){
//        //cs
//        //giveid  openid  nickname  code  mid top_mid  give_rec_id
//
//        $CardPuttest = new CardPuttest();
//        $data['giveid'] = 50;
//        $data['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $data['nickname'] = '自行车';
//        $data['code'] = '128546144267';
//        $data['mid'] = '501';
//        $data['top_mid'] = '1';
//        $data['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $data['give_rec_id'] = '14221';
//        $res = $CardPuttest->firecards($data);
//        halt($res);
//    }
//
//    //补积分
//    public function rec_bonus(){
//        $arr['card_id'] = 'pePs8v3mm3nHv2YmOVceVeLllNvI';
//        $arr['code'] = '135701869905';
//        $arr['bonus'] = 4;
//        $options = $this->options($arr['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data = [
//            'code' => $arr['code'],
//            'card_id' => $arr['card_id'],
////                'record_bonus' => $arr['record_bonus'],       //说明
//            'bonus' => $arr['bonus'],             //积分变动值  负数为减少
//            'notify_optional' => [
//                'is_notify_bonus' => false,
//                'is_notify_balance' => false,
//                'is_notify_custom_field1' => false,
//            ],
//        ];
//        $res = $WxObj->updateUserInfo($data);
//        var_dump($res);
//    }
//
//    public function testfireb(){
//
//    }
//
//    //激活补卡
////    public function firereccard(){
////        $Cardacitvate = new Cardacitvate();
////
////        $data['openid'] = 'o4Rm10zuK56tg54sn4j5Eeopswww';
////        $data['card_id'] = 'p4Rm102mkULKd9f862fXWpOmIaww';
////        $data['code'] = '875863369520';
////
////        $res = $Cardacitvate->getfirecard($data);
////        halt($res);
////    }
//
//    //激活补卡  批量
//    public function firecardall(){
//        $CardUserGet = new CardUserGet();
//        $map['create_time'] = ['GT',1536048000];
//        $map['fire'] = 1;
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['card_id'] = ['neq','pq6bT05pTgqUe_EgboaOU2Qi4p-s'];
//        $list = $CardUserGet->where($map)->field('openid,card_id,code')->select();
////        var_dump(count($list));
////        return json($list);
//        $CardGivecardLog = new CardGivecardLog();
//        $Cardacitvate = new Cardacitvate();
//        foreach ($list as $k=>$v){
//            $rec = $CardGivecardLog->where(['code'=>$v['code']])->count('zs_card_id');
////            if (!$rec){
////                $user = $v;
//////                $res = $Cardacitvate->getfirecard($user);
////
////            }
//        }
//        var_dump(count($rec));
//        return json($rec);
////        $data['openid'] = 'oq6bT06ybLvzhj1GBDCEw711YTg4';
////        $data['card_id'] = 'pq6bT05pTgqUe_EgboaOU2Qi4p-s';
////        $data['code'] = '761384645386';
////        $Cardacitvate = new Cardacitvate();
////        $res = $Cardacitvate->getfirecard($data);
//    }
//
//    public function giftracklist(){
//        $url = 'https://api.weixin.qq.com/card/giftcard/page/batchget?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $data = '{}';
////        return json($data);           Q1wV8H74LpESQylcpThawaUwMXj0ukmjPSDH7Q9I0ig=
//        $res = $this->http_post($url . $AccessToken, $data);
//        var_dump($res);
//
//    }
//
//    public function giftrackstatu(){
//        $url = 'https://api.weixin.qq.com/card/giftcard/maintain/set?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $data['page_id'] = 'Q1wV8H74LpESQylcpThawaUwMXj0ukmjPSDH7Q9I0ig=';
//        $data['maintain'] = true;
////        return json($data);
//        $res = $this->http_post($url . $AccessToken, json_encode($data,JSON_UNESCAPED_UNICODE));
//        var_dump($res);
//    }
//
//    public function updateall(){
//        $Merchant = new Merchant();
//        $map['top_mid'] = 1;
//        $data['auth_type'] = 1;
//        $res = $Merchant->allowField(true)->save($data,$map);
//        var_dump($res);
//    }
//
//
//    //简单激活
//    public function userfire(){
//        $data['membership_number'] = '355854585810';
//        $data['code'] = '355854585810';
//        $data['init_bonus'] = '88';
//        $data['card_id'] = 'pePs8v3mm3nHv2YmOVceVeLllNvI';
//        $open = $this->options($data['card_id']);
//        $wxobj = new Wxobjopen($open);
//        $res = $wxobj->cardFire($data);
//        var_dump($res);
//    }
//
//    public function userbalance()
//    {
//
//        $arr = request()->param();
//        $CardUserGet = new CardUserGet();
//        $map['id'] = 274406;
//        $user = $CardUserGet->where($map)->find();
//        $options = $this->options($user['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data['code'] = $user['code'];
//        $data['card_id'] = $user['card_id'];
//        $data['custom_field_value2'] = $user['balance'].'元';
//        $data['notify_optional']['is_notify_bonus'] = false;
//        $data['notify_optional']['is_notify_balance'] = false;
//        $data['notify_optional']['is_notify_custom_field2'] = false;
////        return json($data);
//        $res = $WxObj->updateUserInfo($data);
//        return json($res);
//
//    }
//
//
//
//    //修改卡券   advanced_info[text_image_list][image_url][]   default_detail
//    public function editcards(){
//        $data['card_id'] = 'pYWlw0aGlzJV4aT8ExIPwm2i2HVY';
//        $data['gift']['base_info']['date_info']['type'] = 'DATE_TYPE_FIX_TIME_RANGE';
//        $data['gift']['base_info']['date_info']['begin_timestamp'] = 1538323200;
//        $data['gift']['base_info']['date_info']['end_timestamp'] = 1543593599;
////        $data['gift']['base_info']['title'] = '皮带';
////        $data['gift']['base_info']['logo_url'] = 'http://mmbiz.qpic.cn/mmbiz_jpg/VtwMJoicTCCXibbvzTOtCyxN1NFMr0ADvTXiaibJeMHHUZBdyUT2hlspDHThYO9Ntib84ibFBn7wGWD06kHlzxnTAcyA/0';
////        $data['gift']['base_info']['color'] = 'Color040';
////        $data['gift']['base_info']['notice'] = '请及时使用';
////        $data['gift']['base_info']['service_phone'] = 1856881682;
////        $data['gift']['base_info']['description'] = '皮带';
////        $data['gift']['base_info']['date_info'] = [];
////        $data['general_coupon']['base_info']['description'] = '此优惠券不兑换现金，不找零（请在结账前出示本劵）
////            此优惠券在有效期内使用，过期无效
////            此优惠券不与其他优惠活动叠加使用
////            此优惠券每次只限使用一张
////            最终解释权归本店所有';
////        $data['gift']['advanced_info']['text_image_list'] = [
////            [
////                'image_url'=>'http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0',
////                'text'=>'此菜品精选食材，以独特的烹饪方法，最大程度地刺激食 客的味蕾',
////            ],
////            [
////                'image_url'=>'http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0',
////                'text'=>'此菜品精选食材，以独特的烹饪方法，最大程度地刺激食 客的味蕾',
////            ]
////        ];
////        return json($data);
//        $open = $this->options($data['card_id']);
//        $wxObj = new Wxobjopen($open);
//        $res = $wxObj->updateUserCard($data);
//
////        $url = 'https://api.weixin.qq.com/card/update?access_token=';
////        $AccessToken = $this->getaccesstoken();
////        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump($res);
//    }
//
//


//
//    //货架链接
//    public function geturlencodes(){
//        $url = 'zQHsPap2k8t0ihHW7Jp7UMyUe/1R1AFr6NGqnKQxDq0=';
//        $res = urlencode($url);
//        $rurl = 'https://mp.weixin.qq.com/bizmall/giftcard?action=homepage&page_id='.$res;
//        var_dump($rurl);
//    }
//
//    //礼品卡核销
//    public function getcardgiftcon(){
//        $data['card_id'] = 'pCVCLv5zEg6-4FrxdQSHH4zf1xTk';
//        $data['code'] = '439393765833';
//        $url = 'https://api.weixin.qq.com/card/code/consume?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump($res);
////        $res = json_decode($res,true);
//
//    }
//
//    //激活方式
//    public function firetype(){
//        $data['card_id'] = 'pCVCLv7Bdh-bCiYNmkFIqfh4fwho';
//        $data['member_card']['wx_activate'] = true;
//        $data['member_card']['wx_activate_after_submit'] = true;
//        $data['member_card']['wx_activate_after_submit_url'] = 'https://os.wunengkeji.com/mobile.php?s=/cardacitvate/cardfire/';
//        $url = 'https://api.weixin.qq.com/card/update?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump(json_decode($res,true));
//    }
//
//    //开卡组件
//    public function openfiretype(){
//        $data['card_id'] = 'pCVCLv9k9W531EH3drfKCaAkKK30';
//        $data['outer_str'] = 'qweq';
//        $url = 'https://api.weixin.qq.com/card/membercard/activate/geturl?access_token=';
//        $AccessToken = $this->getaccesstoken();
//        $res = $this->http_post($url . $AccessToken, json_encode($data, JSON_UNESCAPED_UNICODE));
//        var_dump(json_decode($res,true));
//    }
//
//
//    //领卡
//    public function recgetgift(){
//        $res = '{"openid":"oCVCLvwkYgBzdu1LLaYw5RFPngTs","create_time":"1534757377","card_id":"pCVCLv5zEg6-4FrxdQSHH4zf1xTk","code":"625270618096","isgivecard":"0","have":"0",
//        "sourec":"SOURCE_SCENE_USER_ACCEPT_GIFTCARD","unionid":"oAAAAALd5DIFhRXPS6EwHA28gCMA","card_type":"GENERAL_CARD"}';
//        $data = json_decode($res,JSON_UNESCAPED_UNICODE);
//        $Wxcard = new Wxcard();
//        $ress = $Wxcard->recgetcardgift($data);
//        var_dump($ress);
//    }
//
//    //获取accesstoken
//    public function getaccesstoken(){
//        $Momchant = new Momerchant();
//        $wxOpen = new WxOpen();
//        $map['id'] = Session::get('login_top_mid');
//        $wx_open_id = $Momchant->where($map)->value('wx_open_id');
//        $access = $wxOpen->where(['id'=>$wx_open_id])->value('at_access_token');
//        return $access;
//    }
//
//    //商户号激活
//    public function machidgift(){
//        $open = $this->option(501);
////        var_dump($open);
//        $Wechant = new Wxobjopen($open);
//        $data = ['sub_mch_id'=>'1389929902'];
//        $url  ='https://api.weixin.qq.com/card/giftcard/pay/whitelist/add?access_token=';
//        $accesstoken = '12_JkpHBG4JkptbEQ8wV8no-OFRxgjfOn0bdCR3vk6fsTNWXsky_dSwT_XQWOurKOQ-16ReW2Mah8jrNbTmCBBNTEphduQypUOXmJhnt0i8EIu3c79iW2hSQTsZA7wTR8Qv5IP30_vYHyKmRuKwZOQdAKDSHJ';
//        $res = $this->http_post($url.$accesstoken,json_encode($data,JSON_UNESCAPED_UNICODE));
////        return json($data);
////        $res = $Wechant->applyGiftPayWhitelist($data);
//        var_dump($res);
//    }
//
//    private function http_get($url)
//    {
//        $oCurl = curl_init();
//        if (stripos($url, "https://") !== FALSE) {
//            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
//            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
//            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
//        }
//        curl_setopt($oCurl, CURLOPT_URL, $url);
//        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
//        $sContent = curl_exec($oCurl);
//        $aStatus = curl_getinfo($oCurl);
//        curl_close($oCurl);
//        if (intval($aStatus["http_code"]) == 200) {
//            return $sContent;
//        } else {
//            return false;
//        }
//    }
//
//    private function http_post($url, $param, $post_file = false)
//    {
//        $oCurl = curl_init();
//        if (stripos($url, "https://") !== FALSE) {
//            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
//            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
//            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
//        }
//        if (PHP_VERSION_ID >= 50500 && class_exists('\CURLFile')) {
//            $is_curlFile = true;
//        } else {
//            $is_curlFile = false;
//            if (defined('CURLOPT_SAFE_UPLOAD')) {
//                curl_setopt($oCurl, CURLOPT_SAFE_UPLOAD, false);
//            }
//        }
//        if (is_string($param)) {
//            $strPOST = $param;
//        } elseif ($post_file) {
//
//            if ($is_curlFile) {
//                foreach ($param as $key => $val) {
//
//                    if (substr($val, 0, 1) == '@') {
//
//                        $param[$key] = new \CURLFile(realpath(substr($val, 1)));
//
//                    }
//                }
//
//            }
//            $strPOST = $param;
//
//        } else {
//            $aPOST = array();
//            foreach ($param as $key => $val) {
//                $aPOST[] = $key . "=" . urlencode($val);
//            }
//            $strPOST = join("&", $aPOST);
//
//        }
//
//        curl_setopt($oCurl, CURLOPT_URL, $url);
//        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
//        curl_setopt($oCurl, CURLOPT_POST, true);
//        curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
//        $sContent = curl_exec($oCurl);
//        $aStatus = curl_getinfo($oCurl);
//        curl_close($oCurl);
//
//        if (intval($aStatus["http_code"]) == 200) {
//            return $sContent;
//        } else {
//            return false;
//        }
//    }
//
//
//    public function machcate(){
//
//        $param = '{"category_list":["美食,江浙菜,上海菜","美食,江浙菜,淮扬菜","美食,江浙菜,浙江菜","美食,江浙菜,南京菜","美食,江浙菜,苏帮菜","美食,江浙菜,杭帮菜","美食,江浙菜,宁波菜","美食,江浙菜,无锡菜","美食,江浙菜,舟山菜","美食,江浙菜,衢州菜","美食,江浙菜,绍兴菜","美食,江浙菜,温州菜","美食,江浙菜,苏北土菜","美食,粤菜,潮汕菜","美食,粤菜,茶餐厅","美食,粤菜,客家菜","美食,粤菜,湛江菜","美食,川菜,自贡盐帮菜","美食,川菜,江湖菜","美食,川菜,酸菜鱼","美食,川菜,香锅","美食,川菜,川味小吃","美食,湘菜","美食,东北菜","美食,徽菜","美食,闽菜","美食,鲁菜","美食,台湾菜","美食,西北菜","美食,东南亚菜,泰国菜","美食,东南亚菜,越南菜","美食,东南亚菜,印度菜","美食,东南亚菜,星马菜","美食,东南亚菜,其它东南亚菜","美食,西餐,法国菜","美食,西餐,意大利菜","美食,西餐,俄罗斯菜","美食,西餐,牛排","美食,西餐,比萨","美食,西餐,巴西菜","美食,西餐,中东菜","美食,西餐,西式正餐","美食,西餐,西式简餐","美食,西餐,西班牙菜","美食,西餐,无国界料理","美食,西餐,美国菜","美食,西餐,葡国菜","美食,西餐,地中海菜","美食,西餐,拉美烧烤","美食,西餐,英国菜","美食,西餐,德国菜","美食,西餐,墨西哥菜","美食,西餐,其它西餐","美食,日韩菜,日本菜","美食,日韩菜,韩国菜","美食,日韩菜,其它日韩菜","美食,火锅","美食,清真菜","美食,小吃快餐","美食,海鲜","美食,烧烤","美食,自助餐","美食,面包甜点","美食,茶餐厅","美食,咖啡厅","美食,其它美食,北京家常菜","美食,其它美食,官府菜","美食,其它美食,云贵菜","美食,其它美食,湖北菜","美食,其它美食,山西菜","美食,其它美食,豫菜","美食,其它美食,天津菜","美食,其它美食,新疆菜","美食,其它美食,农家菜","美食,其它美食,创意菜","美食,其它美食,素菜","美食,其它美食,烤鸭","美食,其它美食,江西菜","美食,其它美食,蒙古菜","美食,其它美食,广西菜","美食,其它美食,冀菜","美食,其它美食,陕西菜","美食,其它美食,青海菜","美食,其它美食,西藏菜","美食,其它美食,酒楼","美食,其它美食,家常菜","美食,其它美食,私家菜","美食,其它美食,民族菜","美食,其它美食,冷饮店","美食,其它美食,其它中餐厅","基础设施,交通设施,交通服务相关","基础设施,交通设施,公交车站","基础设施,交通设施,地铁站","基础设施,交通设施,港口码头","基础设施,交通设施,火车站","基础设施,交通设施,轻轨站","基础设施,交通设施,过境口岸","基础设施,交通设施,长途汽车站","基础设施,交通设施,飞机场","基础设施,交通设施,公交线路","基础设施,交通设施,地铁线路","基础设施,交通设施,其它交通设施","基础设施,公共设施,公共厕所","基础设施,公共设施,公用电话","基础设施,公共设施,紧急避难场所","基础设施,公共设施,其它公共设施","基础设施,道路附属,收费站","基础设施,道路附属,服务区","基础设施,道路附属,其它道路附属","基础设施,其它基础设施","医疗保健,专科医院,齿科","医疗保健,专科医院,整形","医疗保健,专科医院,眼科","医疗保健,专科医院,耳鼻喉","医疗保健,专科医院,胸科","医疗保健,专科医院,骨科","医疗保健,专科医院,肿瘤","医疗保健,专科医院,脑科","医疗保健,专科医院,妇产科","医疗保健,专科医院,儿科","医疗保健,专科医院,传染病医院","医疗保健,专科医院,精神病医院","医疗保健,专科医院,其它专科医院","医疗保健,综合医院","医疗保健,诊所","医疗保健,急救中心","医疗保健,药房药店","医疗保健,疾病预防","医疗保健,其它医疗保健","生活服务,家政,月嫂保姆","生活服务,家政,保洁钟点工","生活服务,家政,开锁","生活服务,家政,送水","生活服务,家政,家电维修","生活服务,家政,管道疏通打孔","生活服务,家政,搬家","生活服务,家政,其它家政","生活服务,宠物服务,宠物商店","生活服务,宠物服务,宠物市场","生活服务,宠物服务,宠物医院","生活服务,宠物服务,其它宠物服务","生活服务,旅行社","生活服务,摄影冲印","生活服务,洗衣店","生活服务,票务代售,飞机票代售","生活服务,票务代售,火车票代售","生活服务,票务代售,汽车票代售","生活服务,票务代售,公交及IC卡","生活服务,票务代售,景点售票","生活服务,票务代售,其它票务代售","生活服务,邮局速递,邮局","生活服务,邮局速递,速递","生活服务,通讯服务,中国电信营业厅","生活服务,通讯服务,中国网通营业厅","生活服务,通讯服务,中国移动营业厅","生活服务,通讯服务,中国联通营业厅","生活服务,通讯服务,中国铁通营业厅","生活服务,通讯服务,其它通讯服务","生活服务,彩票,彩票彩券销售点","生活服务,彩票,马会投注站","生活服务,报刊亭","生活服务,自来水营业厅","生活服务,电力营业厅","生活服务,教练","生活服务,生活服务场所","生活服务,信息咨询中心","生活服务,招聘求职","生活服务,中介机构","生活服务,事务所","生活服务,丧葬","生活服务,废品收购站","生活服务,福利院养老院","生活服务,测字风水","生活服务,家装","生活服务,其它生活服务","休闲娱乐,洗浴推拿足疗","休闲娱乐,KTV","休闲娱乐,酒吧","休闲娱乐,咖啡厅","休闲娱乐,茶馆","休闲娱乐,电影院","休闲娱乐,棋牌游戏","休闲娱乐,夜总会","休闲娱乐,剧场音乐厅","休闲娱乐,度假疗养","休闲娱乐,户外活动","休闲娱乐,网吧","休闲娱乐,迪厅","休闲娱乐,演出票务","休闲娱乐,其它娱乐休闲","购物,综合商场","购物,便利店","购物,超市","购物,花鸟鱼虫","购物,家具家居建材","购物,体育户外","购物,服饰鞋包","购物,图书音像","购物,眼镜店","购物,母婴儿童","购物,珠宝饰品","购物,化妆品","购物,食品烟酒","购物,数码家电","购物,农贸市场","购物,小商品市场","购物,旧货市场","购物,商业步行街","购物,礼品","购物,摄影器材","购物,钟表店","购物,拍卖典当行","购物,古玩字画","购物,自行车专卖","购物,文化用品","购物,药店","购物,品牌折扣店","购物,自动售货机","购物,其它购物","运动健身,健身中心","运动健身,游泳馆","运动健身,瑜伽","运动健身,羽毛球馆","运动健身,乒乓球馆","运动健身,篮球场","运动健身,足球场","运动健身,壁球场","运动健身,马场","运动健身,高尔夫场","运动健身,保龄球馆","运动健身,溜冰","运动健身,跆拳道","运动健身,海滨浴场","运动健身,网球场","运动健身,橄榄球","运动健身,台球馆","运动健身,滑雪","运动健身,舞蹈","运动健身,攀岩馆","运动健身,射箭馆","运动健身,综合体育场馆","运动健身,其它运动健身","汽车,加油站","汽车,停车场","汽车,4S店","汽车,汽车维修","汽车,驾校","汽车,汽车租赁","汽车,汽车配件销售","汽车,汽车保险","汽车,摩托车","汽车,汽车养护","汽车,洗车场","汽车,汽车俱乐部","汽车,汽车救援","汽车,二手车交易市场","汽车,车辆管理机构","汽车,其它汽车","酒店宾馆,星级酒店","酒店宾馆,经济型酒店","酒店宾馆,公寓式酒店","酒店宾馆,度假村","酒店宾馆,农家院","酒店宾馆,青年旅社","酒店宾馆,酒店宾馆","酒店宾馆,旅馆招待所","酒店宾馆,其它酒店宾馆","旅游景点,公园","旅游景点,其它旅游景点","旅游景点,风景名胜","旅游景点,植物园","旅游景点,动物园","旅游景点,水族馆","旅游景点,城市广场","旅游景点,世界遗产","旅游景点,国家级景点","旅游景点,省级景点","旅游景点,纪念馆","旅游景点,寺庙道观","旅游景点,教堂","旅游景点,海滩","文化场馆,博物馆","文化场馆,图书馆","文化场馆,美术馆","文化场馆,展览馆","文化场馆,科技馆","文化场馆,天文馆","文化场馆,档案馆","文化场馆,文化宫","文化场馆,会展中心","文化场馆,其它文化场馆","教育学校,小学","教育学校,幼儿园","教育学校,其它教育学校","教育学校,培训","教育学校,大学","教育学校,中学","教育学校,职业技术学校","教育学校,成人教育","银行金融,银行","银行金融,自动提款机","银行金融,保险公司","银行金融,证券公司","银行金融,财务公司","银行金融,其它银行金融","地名地址,交通地名","地名地址,地名地址信息","地名地址,道路名","地名地址,自然地名","地名地址,行政地名","地名地址,门牌信息","地名地址,其它地名地址","房产小区,住宅区","房产小区,产业园区","房产小区,商务楼宇","房产小区,其它房产小区","丽人,美发","丽人,美容","丽人,SPA","丽人,瘦身纤体","丽人,美甲","丽人,写真","丽人,其它","结婚,婚纱摄影","结婚,婚宴","结婚,婚戒首饰","结婚,婚纱礼服","结婚,婚庆公司","结婚,彩妆造型","结婚,司仪主持","结婚,婚礼跟拍","结婚,婚车租赁","结婚,婚礼小商品","结婚,婚房装修","结婚,其它","亲子,亲子摄影","亲子,亲子游乐","亲子,亲子购物","亲子,孕产护理","公司企业,农林牧渔基地","公司企业,企业\/工厂","公司企业,其它公司企业","机构团体,公检法机构","机构团体,外国机构","机构团体,工商税务机构","机构团体,政府机关","机构团体,民主党派","机构团体,社会团体","机构团体,传媒机构","机构团体,文艺团体","机构团体,科研机构","机构团体,其它机构团体","其它"]}';
//        $data = json_decode($param,true);
////        var_dump($data['category_list']);
////        exit();
//        $datas = $data['category_list'];
////        $onec = '';
////        $ones = '';
//
////        foreach ($datas as $key => $value) {
////            $str = explode(',', $value);
//////            if ($str[0] == $key['name']) {
//////
//////
//////            return json($str);
//////            var_dump($str);
////                if (isset($str[0])) {
////                    if ($ones !== $str[0]) {
////                        $onec .= '/' . $str[0];
////                    }
////                    $ones = $str[0];
////                }
////
//////            }
//////            return $onec;
////
//////            }
////        }
////        var_dump($onec);
////        exit();
////        $id = $this->addmachcate($onec);
////        return $id;
//        $onec = '';
//        $ones = '';
//        $MechantCate = new MerchantCate();
//        $list = $MechantCate->where(['level'=>1])->field('id,name')->select();
////        return json($list);
//        foreach ($list as $k=>$v) {
//            foreach ($datas as $key => $value) {
//                $str = explode(',', $value);
//                if ($str[0] == $v['name']) {
////
////
////            return json($str);
////            var_dump($str);
//                    if (isset($str[1])) {
//                        if ($ones !== $str[1]) {
//                            $onec .= '/' . $str[1];
//                        }
//                        $ones = $str[1];
//                    }
//
////            }
//
//
//                }
//                return $onec;
//            }
////            var_dump($onec);
////
////            var_dump(json_encode($v,JSON_UNESCAPED_UNICODE));
//            $id = $v['id'];
////            var_dump($id);
////            return $id;
//            $res = $this->addmachcate($onec,$id);
////            $res = $this->addmachcate($onec);
//        }
//        return json($res);
//        exit();
////        return json($ones);
////        return json($onec);
//        $res = $this->addmachcate($onec);
//        var_dump($res);
//    }
//
//    public function addmachcate($param,$id){
////        $param = '江浙菜/粤菜/川菜/湘菜/东北菜/徽菜/闽菜/鲁菜/台湾菜/西北菜/东南亚菜/西餐/日韩菜/火锅/清真菜/小吃快餐/海鲜/烧烤/自助餐/面包甜点/茶餐厅/咖啡厅/其它美食';
//        $datas = explode('/',$param);
//        $MechantCate = new MerchantCate();
//        foreach ($datas as $k=>$v){
//            if ($v !== '') {
//                $data[$k]['level'] = 2;
//                $data[$k]['parent_id'] = $id;
//                $data[$k]['name'] = $v;
//            }
//        }
////        return $data;
////        return json($data);
//
//        $res = $MechantCate->allowField(true)->saveAll($data);
//        return $res;
//        var_dump($res);
//        exit();
//        return json($data);
//        var_dump($data);
//    }
//
//
//
//    public function testrecpay(){
//        $data['price'] = "98789464645646547464564";
//        $data['yf_price'] = $data['price'];
//        $data['orderid'] = 'H501-2018070511413761122';
//        $data['mid']= 501;
//        $Paylog = new Paylog();
//        $res = $Paylog->save($data);
//        var_dump($res);
//    }
//
//
//    /*
//     * mid   openid  price pay_cate/   pq6bT0wCdmHMMW_ybW75BO6vTxKI
//     * */
//    public function pay_inc_bonus($payinfo){
////        try {
//        if ($payinfo['pay_cate'] == 'pay') {
//            $Merchant = new Merchant();
//            $top_mid = $Merchant->where('id', $payinfo['mid'])->value('top_mid');
//            $midlist = $Merchant->where('top_mid', $top_mid)->field('id')->select();
//            foreach ($midlist as $k => $v) {
//                $midarr[] = $v['id'];
//            }
//            $mid = implode(',', $midarr);
//            $map['mid'] = ['in', $mid];
//            $map['top_mid'] = $top_mid;
//            $map['openid'] = $payinfo['sub_openid'];
//            $map['have'] = 1;
//            $map['fire'] = 1;
//            $map['card_type'] = 'MEMBER_CARD';
//            $CardUserGet = new CardUserGet();
//            $CardUserUpdate = new CardUserUpdate();
//            $userinfo = $CardUserGet->where($map)->field('id,card_id,balance,bonus,code,openid')->find();
//            $is_bonusup = $CardUserUpdate->where(array('card_id' => $userinfo['card_id'], 'code' => $userinfo['code'], 'orderid' => $payinfo['orderid']))->value('orderid');
//            if (!$is_bonusup) {
//                if ($userinfo) {
//                    $CardMember = new CardMember();
//                    $Bonus = new Bonus();
//                    //更新积分
//                    $card = $CardMember->where('card_id', $userinfo['card_id'])->field('supply_bonus,bonus_rule')->find();
//                    //判断是否开启积分
//                    if ($card['supply_bonus'] == 1) {
//                        $bonus_rule = json_decode($card['bonus_rule'], true);
//                        //比例和积分
//                        $bili = @($bonus_rule['increase_bonus'] / $bonus_rule['cost_money_unit']);
//                        $add_bonus = floor($payinfo['price'] * $bili);
//                        //同步微信数据
//                        $bonus['code'] = $userinfo['code'];
//                        $bonus['card_id'] = $userinfo['card_id'];
//                        $bonus['record_bonus'] = '消费赠送';
//                        $bonus['add_bonus'] = $add_bonus;
//                        $resu['bonus'] = $Bonus->bonusgive($bonus);
//                        //判断更新
//                        if ($resu['bonus']['errcode'] == 0) {
//
//                            $datas['orderid'] = $payinfo['orderid'];
//                            $datas['code'] = $userinfo['code'];
//                            $datas['card_id'] = $userinfo['card_id'];
//                            $datas['openid'] = $userinfo['openid'];
//                            $datas['record_bonus'] = $bonus['record_bonus'];    //
//                            $datas['hx_fs'] = $payinfo['pay_fs'];            //方式
//                            $datas['type'] = 6;             //类型
//                            $datas['cate'] = 1;             //类别
//                            $datas['reason'] = 1;           //原因
////                            $datas['source'] = $param['source'];           //来源
//                            $datas['mid'] = $payinfo['mid'];
//                            $datas['add_bonus'] = $resu['bonus']['add_bonus'];
//                            $datas['con_username'] = $payinfo['d_cashier'];
//                            $datas['create_time'] = time();
//                            $CardUserUpdate->allowField(true)->save($datas);
//                            $record_id = $CardUserUpdate->id;
//                            //carduserlog 记录
//                            $datas['up_id'] = $record_id;
//                            $res = $Bonus->rec_cardlogs($datas);
//                            if ($res) {
//                                $bonusdata['code'] = 0;
//                                $bonusdata['message'] = $resu;
//                                $bonusdata['add_bonus'] = $add_bonus;
//                            } else {
//                                $bonusdata['code'] = 0;
//                                $bonusdata['message'] = $resu;
//                                $bonusdata['add_bonus'] = $add_bonus;
//                            }
//                        } else {
//                            $bonusdata = ['code' => 9002, 'message' => $resu, 'add_bonus' => $add_bonus];
//                        }
//                    } else {
//                        $bonusdata = ['code' => 9003, 'message' => '无积分', 'add_bonus' => ''];
//                    }
//                } else {
//                    $bonusdata = ['code' => 9004, 'message' => '无此会员', 'add_bonus' => ''];
//                }
//            } else {
//                $bonusdata = ['code' => 9005, 'message' => '已赠送', 'add_bonus' => ''];
//            }
//        }else{
//            $bonusdata = ['code' => 9006, 'message' => '非支付', 'add_bonus' => ''];
//        }
//
////        }catch (\Exception $e){
////            $bonusdata = ['code' => 9001, 'message' => '非支付', 'add_bonus' => ''];
////        }
//        return $bonusdata;
//    }
//
//
//
//    /*
//   * 积分规则
//   * card_id(会员卡ID)，add_bonus(变动积分)，record_bonus（变动说明）code（用户会员卡编号）
//   *
//   */
//    public function bonusgive($arr)
//    {
//        $CardBonusRule = new CardBonusRule();
////        $arr = [];
//        $Bonus = new Bonus();
//        //禁止规则
//        $map['end_time'] = ['egt', time()];
//        $map['card_id'] = $arr['card_id'];
//        $map['type'] = 1;
//        $map['statu'] = 0;
//        $ruledis = $CardBonusRule->where($map)->find();
//        if (empty($ruledis)) {
//            //多倍规则
//            $mab['end_time'] = ['egt', time()];
//            $mab['card_id'] = $arr['card_id'];
//            $mab['type'] = 2;
//            $mab['statu'] = 0;
//            $rulemax = $CardBonusRule->where($mab)->find();
//            //多倍积分
//            if ($rulemax) {
//                $CardUserGet = new CardUserGet();
//                $barr['add_bonus'] = $arr['add_bonus'] * $rulemax['bonus_max'];               //积分变动
//                $barr['card_id'] = $arr['card_id'];                                         //卡券ID
//                $barr['code'] = $arr['code'];                                               //卡券CODE
//                $barr['record_bonus'] = $arr['record_bonus'];                               //说明
//                $res = $Bonus->updatebonus($barr);
//                if ($res['errcode'] == 0) {
//                    $mad['card_id'] = $arr['card_id'];
//                    $mad['code'] = $arr['code'];
//                    $CardUserGet->where($mad)->setField('bonus', $res['result_bonus']);
//
//                    $datas = $res;
//                } else {
//                    $datas = ['msg' => $res['errmsg'], 'code' => '9002'];
//                }
//                //普通积分
//            } else {
//                $CardUserGet = new CardUserGet();
//                $barr['add_bonus'] = $arr['add_bonus'];               //积分变动
//                $barr['card_id'] = $arr['card_id'];                                         //卡券ID
//                $barr['code'] = $arr['code'];                                               //卡券CODE
//                $barr['record_bonus'] = $arr['record_bonus'];                               //说明
//                $res = $Bonus->updatebonus($barr);
//                if ($res['errcode'] == 0) {
//                    $mad['card_id'] = $arr['card_id'];
//                    $mad['code'] = $arr['code'];
//                    $CardUserGet->where($mad)->setField('bonus', $res['result_bonus']);
//
//                    $datas = $res;
//                } else {
//                    $datas = ['msg' => $res['errmsg'], 'code' => '9002'];
//                }
//            }
//        } else {
//            $datas = ['msg' => '该时间段内不可积分', 'code' => '9004'];
//        }
//        return $datas;
//    }
//
//    //会员信息
//    public function getcarduserinfo($params)
//    {
//        try {
//            $Merchant = new Merchant();
//            $top_mid = $Merchant->where('id', $params['merchid'])->value('top_mid');
//            $midlist = $Merchant->where('top_mid', $top_mid)->field('id')->select();
//            foreach ($midlist as $k => $v) {
//                $midarr[] = $v['id'];
//            }
//            $mid = implode(',', $midarr);
//            $map['mid'] = ['in', $mid];
//            $map['top_mid'] = $top_mid;
//            $map['openid'] = $params['openid'];
//            $map['have'] = 1;
//            $map['fire'] = 1;
//            $map['card_type'] = 'MEMBER_CARD';
//            $Wxusergetcard = new CardUserGet();
//            $userinfo = $Wxusergetcard->where($map)->find();
//
//        } catch (\Exception $e) {
//            $userinfo = array('code' => '9099', 'message' => '系统错误');
//
//        }
//        return json($userinfo);
//    }
//
//    public function testasd(){
//        $CardUserGet = new CardUserGet();
//
//        $map['card_id'] = 'pAldkw907QzSqht75Sb98Obh3eW8';
//        $map['card_type'] = 'MEMBER_CARD';
//        $map['fire'] = '1';
//        $map['fire_time'] = ['gt',1530115200];
//        $map['fire_time'] = ['lt',1530201599];
//        $userlist = $CardUserGet->where($map)->field('card_id,code,openid,nickname,top_mid,mid,fire')->select();
//        $CardPut = new CardPut();
//        foreach ($userlist as $k=>$v){
//            $res[] = $CardPut->firecards($v);
//        }
//        return json($res);
//
//
//        $Paylog = new Paylog();
//        $mab['price'] = 38;
//        $mab['mid'] = 622;
//        $mab['pay_statu'] = 1;
//        $paylist = $Paylog->where($mab)->field('orderid,openid,add_time')->select();
//        return json($userlist);
//
//        $data['mid'] = '622';
//        $data['openid'] = '';
//        $data['card_id'] = '';
//        $data['give_rec_id'] = '';
//        $data['top_mid'] = '';
//        $data['code'] = '';
//        $data['zs_card_id'] = '';
//        $data['put_sume'] = '';
//        $data['put_type'] = '';
//        $data['create_time'] = time();
//        $data['openid'] = '';
//        $data['openid'] = '';
//        $data['openid'] = '';
//        $data['openid'] = '';
//    }
//
//    public function testfires(Request $request){
//        $param = $request->param();
//        $CardGetUser = new CardUserGet();
//        $Momerchant = new Momerchant();
//        $WxOpen = new WxOpen();
//        $user = $CardGetUser->where(['code'=>$param['code']])->field('code,card_id,openid,top_mid')->find();
//        $wx_open = $Momerchant->where('id',$user['top_mid'])->value('wx_open_id');
//
//        $arr['cardid'] = $user['card_id'];
//        $arr['usercardcode'] = $param['code'];
//        $arr['openid'] = $user['openid'];
//        $arr['gh_id'] = $WxOpen->where('id',$wx_open)->value('gh_id');
//
//        $res = action('index/wxcard/userfirecard',[$arr]);
//
//        var_dump($res);
//    }
//
//    public function cardstatu(){
//        $data['card_id']="pCVCLv8UyHl7WUhqSIvj4i3s5uO8";
//        $data['code']="192375603221";
//        $open = $this->options($data['card_id']);
////        var_dump($open);
////        exit();
//        $wxObj = new Wxobjopen($open);
//        $res = $wxObj->getCardState($data);
//        var_dump($res);
//    }
//
//    public function cackpay(){
//        $pay = new \app\api\controller\Pay();
//        $data['merchid'] = '696';
//        $data['orderid'] = 'H696-20180924173140333026';
//        $res = $pay->orderquery($data['merchid'],$data['orderid']);
//        var_dump($res);
//    }
//
//    public function tojson(){
//        $info="
//
//        ------------------------------
//        商户名称：{merchantname}
//        交易单号：{no}
//        支付方式：{paymode}
//        付款时间：{paytime}
//        操 作 员：{cashier}
//
//
//        实付金额：￥{total}
//        订单金额：￥{ought}
//        {addo_popup}
//        \r\n
//        ------------------------------
//        客户签字：\r\n\r\n";
//        var_dump(json_encode($info,JSON_UNESCAPED_UNICODE));
//    }
//
//
//
//    public function testaddgift(){
//        $data = '{
//    "card": {
//        "card_type": "GENERAL_CARD",
//        "general_card": {
//            "sub_card_type": "GIFT_CARD",
//            "background_pic_url": "https://mmbiz.qlogo.cn/mmbiz/",
//            "base_info": {
//                "max_give_friend_times": 1,
//                "giftcard_info": {
//                    "price": 1
//                },
//                "logo_url": "https://mmbiz.qlogo.cn/mmbiz/p98FjXy8LaeMq67mEpDmkj05EtiaVcGOibVaVux3Agib1ibcHFkCoic7HuQWFawx9XGCNWIO085drjdxTib2nBHlYGAA/0?wx_fmt=gif",
//                "brand_name": "智慧商圈",
//                "code_type": "CODE_TYPE_QRCODE",
//                "title": "测试卡",
//                "color": "Color020",
//                "notice": "使用时向服务员出示",
//                "service_phone": "020-6142228",
//                "description": "不可与其他优惠同享",
//                "date_info": {
//                    "type": "DATE_TYPE_FIX_TIME_RANGE",
//                    "begin_timestamp": 1533830400,
//                    "end_timestamp": 1535558400
//                },
//                "sku": {
//                    "quantity": 100
//                },
//                "get_limit": 1,
//                "use_custom_code": false,
//                "can_give_friend": true,
//                "location_id_list": [
//                    213059884
//                ],
//                "center_title": "顶部居中按钮",
//                "center_sub_title": "按钮下方的wording",
//                "center_url": "www.qq.com",
////                "center_app_brand_user_name": "gh_86a091e50ad4@app",
////                "center_app_brand_pass": "pages/index/index",
//                "custom_url_name": "新品推荐",
//                "custom_url": "https://www.starbucks.com.cn/",
////                "custom_app_brand_user_name": "gh_86a091e50ad4@app",
////                "custom_app_brand_pass": "pages/index/index",
//                "need_push_on_view": true
//            },
//            "advanced_info": {
//                "text_image_list": [
//                    {
//                        "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
//                        "text": "此菜品精选食材，以独特的烹饪方法，最大程度地刺激食 客的味"
//                    },
//                    {
//                        "image_url": "http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sj piby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
//                        "text": "此菜品迎合大众口味，老少皆宜，营养均衡"
//                    }
//                ]
//            },
//            "supply_balance": true,
//            "prerogative": "礼品卡享受更多优惠",
//            "auto_activate": true,
//            "init_balance": 10000,
//            "custom_field1": {
//                "name": "优惠券",
//                "url": "http://wunengkeji.net/index.html",
//                "app_brand_user_name": "",
//                "app_brand_pass": ""
//            },
//            "custom_field2": {
//                "name": "兑换券",
//                "url": "http://wunengkeji.net/index.html",
//                "app_brand_user_name": "",
//                "app_brand_pass": ""
//            }
//        }
//    }
//}';
//        $datas = json_decode($data,true);
//        var_dump($datas);
//        $mid = 501;
//        $open = $this->option($mid);
//        $Wechant = new Wxobjopen($open);
//        $res = $Wechant->createUserCard($datas);
//        return json($res);
//        var_dump();
////        $datas = json_decode($data,true);
////        var_dump($data);
//    }
//
//
//    //设置过期
//    public function hxcardus(Request $request){
//
//        $card_id = 'pCVCLvwA5wzSnVJbquqrHL2SgD-E';
//        $param = $request->param();
//        $CardMember = new CardMember();
////            $data['card_id'] = $card_id;
//        $data['code'] = $param['code'];
//        $data['reason'] = '卡券过期';
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->delineUserCard($data);
//        return json($res);
//        if ($res['errcode'] == 0) {
////                $CardMember->where('card_id', $card_id)->delete();
////                $CardUserGet = new CardUserGet();
////                $CardUpdate = new CardUserUpdate();
////                $CardGivecardLog = new CardGivecardLog();
////                $CardGivecardLog->where(['card_id' => $card_id])->delete();
////                $CardUpdate->where(['card_id' => $card_id])->delete();
////                $CardUserGet->where(['card_id' => $card_id])->delete();
//            echo '删除成功';
//        } else {
//            //错误提示翻译
//            $Helpinfo = new Helpinfo();
//            $errmsg = $Helpinfo->gethelpinfo(0,$res['errcode'],$res['errmsg']);
//            //END
//            $this->error('删除失败-'.$res['errcode'].':' . $errmsg, 'cardus/carduslist', '', 3);
//        }
//
//    }
//
//    public function userbonus(Request $request){
//        if ($request->post()) {
//            Debug::remark('begin');
//            // 进行统计区间
//            $param = $request->post();
////            return json($param);
//            $CardUserUpdate = new CardUserUpdate();
//            //        $map['create_time'] = ['GT',1533052800];
//            $CardUserGet = new CardUserGet();
//            $mab['card_type'] = 'MEMBER_CARD';
//            $mab['fire'] = 1;
//            $mab['create_time'] = ['LT', 1535731200];
//            $userlist = $CardUserGet->where($mab)->field('id,card_id,top_mid,mid,code,bonus,balance,create_time,openid')->limit($param['ks'], $param['end'])->select();
//            $userlist = collection($userlist)->toArray();
//            $CardUserBonus = new CardUserBonus();
//            $CardMember = new CardMember();
//            $time = time();
//            $i = 0;
//            foreach ($userlist as $k => $v) {
//                $map['code'] = $v['code'];
//                $map['create_time'] = ['GT', 1535731200];
//                $data[$i] = $v;
//                $add_bonus = $CardUserUpdate->where($map)->sum('add_bonus');
//                $del_bonus = $CardUserUpdate->where($map)->sum('del_bonus');
//                $data[$i]['c_id'] = $CardMember->where('card_id', $v['card_id'])->value('id');
//                $data[$i]['num'] = $v['bonus'] - $add_bonus + $del_bonus;
//                $data[$i]['us_id'] = $v['id'];
//                $data[$i]['type'] = 999;
//                $data[$i]['mode'] = 999;
//                $data[$i]['cate'] = 999;
//                $data[$i]['source'] = 999;
//                $data[$i]['remark'] = '9/1统计';
//                $data[$i]['create_time'] = $time;
//                unset($data[$i]['id']);
//                $i = $i + 1;
//            }
//            $res = $CardUserBonus->allowField(true)->saveAll($data);
//            $usersum = $CardUserBonus->count();
//            Debug::remark('end');
//            echo Debug::getRangeTime('begin', 'end') . 's';
//            echo "</br>";
//            echo $usersum;
//            echo "</br>";
//            echo count($data);
//
////            return json($res);
//        }
//        $param = $request->param();
////        var_dump($param);
//        if (isset($param['ks']) && $param['end']) {
//            $arrss['ks'] = $param['ks'] + $param['end'];
//            $arrss['end'] = $param['end'];
//        }else{
//            $arrss['ks'] = 0;
//            $arrss['end'] = 500;
//        }
//        $this->assign('info',$arrss);
//        return $this->fetch();
//    }
//
//
//    public function userbalances(Request $request){
//        if ($request->post()) {
//            Debug::remark('begin');
//            // 进行统计区间
//            $param = $request->post();
////            return json($param);
//            $CardUserUpdate = new CardUserUpdate();
//            //        $map['create_time'] = ['GT',1533052800];
//            $CardUserGet = new CardUserGet();
//            $mab['card_type'] = 'MEMBER_CARD';
//            $mab['fire'] = 1;
//            $mab['create_time'] = ['LT', 1535731200];
//            $userlist = $CardUserGet->where($mab)->field('id,card_id,top_mid,mid,code,balance,create_time,openid')->limit($param['ks'], $param['end'])->select();
//            $userlist = collection($userlist)->toArray();
//            $CardUserFee = new CardUserFee();
//            $CardMember = new CardMember();
//            $time = time();
//            $i = 0;
//            foreach ($userlist as $k => $v) {
//                $map['code'] = $v['code'];
//                $map['create_time'] = ['GT', 1535731200];
//                $data[$i] = $v;
//                $add_bonus = $CardUserUpdate->where($map)->sum('add_balance');
//                $del_bonus = $CardUserUpdate->where($map)->sum('del_balance');
//                $data[$i]['c_id'] = $CardMember->where('card_id', $v['card_id'])->value('id');
//                $data[$i]['num'] = $v['balance'] - $add_bonus + $del_bonus;
//                $data[$i]['us_id'] = $v['id'];
//                $data[$i]['type'] = 999;
//                $data[$i]['mode'] = 999;
//                $data[$i]['cate'] = 999;
//                $data[$i]['source'] = 999;
//                $data[$i]['remark'] = '9/1统计';
//                $data[$i]['create_time'] = $time;
//                unset($data[$i]['id']);
//                $i = $i + 1;
//            }
//            $res = $CardUserFee->allowField(true)->saveAll($data);
//            $usersum = $CardUserFee->count();
//            Debug::remark('end');
//            echo Debug::getRangeTime('begin', 'end') . 's';
//            echo "</br>";
//            echo $usersum;
//            echo "</br>";
//            echo count($data);
//
////            return json($res);
//        }
//        $param = $request->param();
////        var_dump($param);
//        if (isset($param['ks']) && $param['end']) {
//            $arrss['ks'] = $param['ks'] + $param['end'];
//            $arrss['end'] = $param['end'];
//        }else{
//            $arrss['ks'] = 0;
//            $arrss['end'] = 500;
//        }
//        $this->assign('info',$arrss);
//        return $this->fetch();
//    }
//
//
//
//    public function delcards()
//    {
//        //pCVCLv3pK-SMO2xosWUjdrUD06_w
//        $card_id = 'pFQIP1Ja9oMHQf_E1WhJolt_D50E';
////        if ($card_id && $this->checkcardid($card_id)) {
//        $CardMember = new CardMember();
//        $data['card_id'] = $card_id;
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->delUserCard($data);
//
//        if ($res['errcode'] == 0) {
//            $CardMember->where('card_id', $card_id)->delete();
//            $CardUserGet = new CardUserGet();
//            $CardUpdate = new CardUserUpdate();
//            $CardGivecardLog = new CardGivecardLog();
//            $CardUserFee = new CardUserFee();
//            $CardUserBonus = new CardUserBonus();
//            $CardUserFee->where(['card_id' => $card_id])->delete();
//            $CardUserBonus->where(['card_id' => $card_id])->delete();
//            $CardGivecardLog->where(['card_id' => $card_id])->delete();
//            $CardUpdate->where(['card_id' => $card_id])->delete();
//            $CardUserGet->where(['card_id' => $card_id])->delete();
//            echo '删除成功';
//        } else {
//            //错误提示翻译
//            $Helpinfo = new Helpinfo();
//            $errmsg = $Helpinfo->gethelpinfo(0,$res['errcode'],$res['errmsg']);
//            //END
//            $this->error('删除失败-'.$res['errcode'].':' . $errmsg, 'cardus/carduslist', '', 3);
//        }
////        }else{
////            $this->success('您没有修改该会员卡操作权限。', 'cardus/carduslist');
////        }
//    }
//
//    public function testgetcardsss(){
//        $data["ToUserName"]="gh_7cce5f015893";
//        $data["FromUserName"]="oCVCLvxU9_O12B0jraMm5wYABguE";
//        $data["CreateTime"]="1528940420";
//        $data["MsgType"]="event";
//        $data["Event"]="user_get_card";
//        $data["CardId"]="pCVCLvxq-8Yf93uaEfJ1Ky3dl5EA";
//        $data["IsGiveByFriend"]="0";
//        $data["UserCardCode"]="409333058883";
//        $data["FriendUserName"]='';
//        $data["OuterId"]="0";
//        $data["OldUserCardCode"]='';
//        $data["IsRestoreMemberCard"]="0";
//        $data["IsRecommendByFriend"]="0";
//        $data["SourceScene"]="SOURCE_SCENE_APPMSG_JSAPI";
//        $data["UnionId"]="oAAAAAMX0OA3CHIqIuIq1k4-8l5c";
//        $Wxcard = new Wxcard();
//        $res = $Wxcard->usergetcard($data);
//        var_dump($res);
//    }
//
//    public function testnotget(){
//        $CardPut = new CardPut();
//        $arr['gh_id'] = 'gh_7cce5f015893';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $res = $CardPut->sendcardsnotice($arr);
//        var_dump($res);
//    }
//
//
//    public function testgive(){
//        $CardGivecardLog = new CardGivecardLog();
//        $map['id'] = ['in',[35462,36174,36175,36176,36325,44169,44170,44171,44183,44195,49964,49965,49966,49967,58741,59055,59057]];
//        $list = $CardGivecardLog->where($map)->select();
//        var_dump(json_encode($list));
////        return json($list);
//    }
//
//    public function gxcards(){
//        $CardGen = new CardGeneral();
//        $map['card_id'] = ['eq',''];
//        $data['advanced_info'] = '';
//        $CardGen->allowField(true)->save();
//    }
//    //本月所有日期
//    public function getyuelist(){
//        $num = date("t"); //获取当前月份天数
//        $start_time = strtotime(date('Y-m-01'));  //获取本月第一天时间戳
//        $array = array();
//        for($i=0;$i<$num;$i++){
//            $array[] = $start_time+$i*86400; //每隔一天赋值给数组
//        }
//        var_dump($array);
//    }
//
//    //日报发送
//    public function testbiaobao(){
//        $Baobiao = new Baobiaotest();
//        $res = $Baobiao->baobiao();
//        var_dump($res);
//    }
//
//    //消息队列
//    public function gettest(){
////        $Tstatis = new Tstatis();
//        $Baobiao = new Baobiao();
//        $res = $Baobiao->baobiao();
//        var_dump($res);
//    }
//
//    //
//    public function getstrlen(){
//        $openid = 'oZBNw0XhTrnPpPChIsujkMzHQBnE';
//        $res = strlen($openid);
//        echo $openid.':'.$res;
//    }
//
//    public function testsq(){
//        $qwe = 18;
//        $res = floor($qwe);
//        var_dump($res);
//    }
//
//    //
//    public function testshare(){
//        $arr['card_id'] = 'pCVCLv7Bdh-bCiYNmkFIqfh4fwho';
//        $arr['code'] = '808379936395';
//        $arr['bonus'] = '10';
//        $arr['record_bonus'] = 'asdasdasd';
//        $Card = new Wxcard();
//        $res = $Card->synusers($arr);
//        var_dump($res);
//    }
//
//    public function filtercardterm(){
//        $card_id = 'pCVCLvwAzepAhq4sx6QOPArHAkcs';
//        $code = '221816468322';
//        $CardGel = new \app\common\model\CardGeneral();
//        $card = $CardGel->where('card_id', $card_id)->field('end_timestamp,stocks,consume,time_type,fixed_term')->find();
//        $time = time();
//        if ($card['time_type'] == 'DATE_TYPE_FIX_TERM'){
//            var_dump(1);
//            $CardUserGet = new \app\common\model\CardUserGet();
//            $user = $CardUserGet->where(['card_id'=>$card_id,'code'=>$code])->field('create_time,have,statu')->find();
//            $jia_time = 86400*$card['fixed_term'];
//            $end_time = strtotime($user['create_time'])+$jia_time;
//            var_dump($jia_time);
//            var_dump(strtotime($user['create_time']));
//            var_dump($end_time);
//            var_dump($time);
//            if ($end_time < $time){
//                var_dump(2);
//                $res = false;
//            }else{
//                var_dump(3);
//                $res = true;
//            }
//        }else{
//            if ($card['end_timestamp'] < $time){
//                var_dump(4);
//                $res = false;
//            }else{
//                var_dump(5);
//                $res = true;
//            }
//        }
//        var_dump($res);
////        return $res;
//    }
//
//    public function testfansoption(){
//        $gh_id = 'gh_7cce5f015893';
//        $res = $this->options2($gh_id);
//        var_dump($res);
//    }
//
//    public function options2($gh_id)
//    {
//        $System = new System();
//        $WxOpen = new WxOpen();
//        $Momerchant = new Momerchant();
//        $Agent = new Agent();
//        $mab['gh_id'] = $gh_id;
//        $users = $WxOpen->where($mab)->find();
//        $agent = $Momerchant->where(array('wx_open_id'=>$users['id']))->value('agent');
//        $config = $Agent->where(array('id' => $agent))->find();
//
//        $options = array(
//            'component_token' => $config['component_token'], // 填写你设定的key
//            'component_encodingaeskey' => $config['component_encodingaeskey'], // 填写加密用的EncodingAESKey
//            'component_appid' => $config['component_appid'], // 填写高级调用功能的app id
//            'component_appsecret' => $config['component_appsecret'], // 填写高级调用功能的密钥
//            'open_ticket' => $config['open_ticket'],
//            'authorizer_appid' => $users['authorizer_appid'],
//            'authorizer_refresh_token' => $users['authorizer_refresh_token'],
//        );
//        return $options;
//    }
//
//    public function hxpricenotz()
//    {
//
//        $arr = request()->param();
//        $CardUserGet = new CardUserGet();
//        $map['id'] = 297017;
//        $user = $CardUserGet->where($map)->find();
//        $options = $this->options($user['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data['code'] = $user['code'];
//        $data['card_id'] = $user['card_id'];
//        $data['custom_field_value2'] = $user['balance'].'元';
//        $data['notify_optional']['is_notify_bonus'] = false;
//        $data['notify_optional']['is_notify_balance'] = false;
//        $data['notify_optional']['is_notify_custom_field2'] = false;
//        $res = $WxObj->updateUserInfo($data);
//        return json($res);
//
//    }
//
//    //常用链接
//    public function cardusLink()
//    {
//        $request = Request::instance();
//        $card_id = request()->param('card_id');
//        $card['card_id'] = $card_id;
//        $card['sharelink'] = $request->domain() . '/mobile.php?s=/cardmarke/cardshare/card_id/' . $card_id;     //分享
//        $card['openlink'] = $request->domain() . '/mobile.php?s=/carduser/opencard/card_id/' . $card_id;     //打开卡
//        $card['reglink'] = $request->domain() . '/mobile.php?s=/carduser/recharge/card_id/' . $card_id;      //充值
//        $card['userlink'] = $request->domain() . '/mobile.php?s=/carduser/index/card_id/' . $card_id;     //会员中心
//        $card['balancelink'] = $request->domain() . '/mobile.php?s=/carduser/balance/card_id/' . $card_id;     //余额
//        $card['shoplink'] = $request->domain() . '/mobile.php?s=/cardshop/goods/card_id/' . $card_id;     //积分商城
//        $this->assign('card', $card);
//        return $this->fetch();
//    }
//
//    public function testisuser(){
//        $arr['card_id'] = 'pUwXAwV90AwvmmmBwBGf3Vslunms';
//        $arr['code'] = '621355540339';
//        $res = $this->iscardcode($arr);
//        var_dump($res);
//    }
//
//    //卡号记录是否存在
//    public function iscardcode($arr){
//        $CardUserget = new CardUserGet();
//        $mapis['card_id'] = $arr['card_id'];
//        $mapis['code'] =  $arr['code'];
//        $isusercode = $CardUserget->where($mapis)->value('openid');          //判断是否存在
//        return $isusercode;
//
////        try {
//
//        $map['card_id'] = $arr['card_id'];
//        $map['code'] = $arr['code'];
////        file_put_contents('/data2/html/payos/test.txt', 'isuser-0:' . json_encode($map), FILE_APPEND);
//        $user = $CardUserget->where($map)->value('openid');
////        file_put_contents('/data2/html/payos/test.txt', 'isuser-1:' . json_encode($CardUserget->getLastSql()), FILE_APPEND);
////        file_put_contents('/data2/html/payos/test.txt', 'isuser-2:' . json_encode($user), FILE_APPEND);
//        if ($user){
//            $res = 1;
//        }else{
//            $res = 0;
//        }
////        file_put_contents('/data2/html/payos/test.txt', 'isuser-3:' . json_encode($res), FILE_APPEND);
////        } catch (\Exception $e) {
////            $res = 0;
////            file_put_contents('/data2/html/payos/test.txt', 'isuser-3:' . json_encode($e->getMessage()), FILE_APPEND);
////        }
////        file_put_contents('/data2/html/payos/test.txt', 'isuser-4:' . json_encode($res, FILE_APPEND));
//        return $res;
//    }
//
//    //
//    public function getczlist(){
//        $arr['type'] = 'card_cz_list';
//        $arr['merchid'] = '501';
//        $res = action('api/api/api',[$arr]);
//        var_dump($res);
//    }
//
//    public function testfollow(){
//        $CardPut = new CardPut();
//        $arr['gh_id'] = 'gh_7cce5f015893';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $res = $CardPut->followcardput($arr);
//        var_dump($res);
//    }
//
//    //获取规则赠券
//    public function givecards($rec_id = 2255){
//        $CardCzLog = new CardCzLog();
//        $CardCzgive = new CardCzgive();
//        $give_id = $CardCzLog->where(['id'=>$rec_id])->value('giveid');
//        $zs_card_all = $CardCzgive->where(['id'=>$give_id])->value('zs_card_id_all');
//        $res = getgivecardnew($zs_card_all,0);
//        var_dump($res);
//    }
//
//    public function test(){
//        $id = '15073';
////        $Paylog= new Paylog();
////        $pay = $Paylog->where(['id'=>$id])->find();
//        $updata['mid'] =123;
//        $updata['openid'] = 234;
//        $updata['price'] = 345;
//        $updata['orderid'] = 456;
//        $updata['get_card_id'] = 567;
//        $updata['type'] = 678;
//        $res = $this->recdata($updata);
//        var_dump($res);
//    }
//
//    //将发送数据写入文件
//    public function recdata($arr){
//        try {
//            file_put_contents('/data2/html/payos/exelog/' . date("Y-m-d") . '.txt', $arr['type'] . '-' . json_encode($arr, JSON_UNESCAPED_UNICODE), FILE_APPEND);
//        } catch (\Exception $e) {
//            $data2 = array('code' => '9099', 'message' => $e->getMessage());
//            return $data2;
//        }
//    }
//
//    //
//    public function paytest(){
//        $arr['type'] = 'card_cz_que';
//        $arr['merchid'] = '501';
//        $arr['price'] = '110';
//        $arr['orderid'] = '';
//        $arr['code'] = '819240230226';
//        $arr['user'] = 'qwe';
//        $arr['csid'] = '';
//        $arr['cate'] = 'price';
//        $res = action('api/api/api',array($arr));
//        var_dump($res);
//    }
//
//    //{"card_id":"pCVCLv7Bdh-bCiYNmkFIqfh4fwho","code":"826844772669","openid":"oCVCLv2epPfR-zgO8v3HE7y5yjsw","nickname":"可参","top_mid":"1","mid":"501","give_type":"fire_card"}
//    public function testfire(){
//        $arr['card_id'] = 'pCVCLv7Bdh-bCiYNmkFIqfh4fwho';
//        $arr['code'] = '940062171091';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $arr['nickname'] = '可参';
//        $arr['top_mid'] = '1';
//        $arr['mid'] = '501';
//        $arr['give_type'] = 'fire_card';
//        $CardPut = new CardPut();
//        $res = $CardPut->firecards($arr);
//        var_dump($res);
//    }
//
//    //
//    public function testpaycardnu(){
//        $arr['mid'] = 501;
//        $appid = 'wx26dd3a738e5b357c';
//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $CardShop = new Cardshop();
//        $res = $CardShop->isgetcardus($appid,$card_id,$arr);
//        var_dump($res);
//    }
//
//    //更新积分余额
//    public function updata_card_infos($updata)
//    {
//        $CardUserGet = new CardUserGet();
//        $CardCzLog = new CardCzLog();
//        $ComBalance = new Balance();
//        $ComCardPut = new \app\common\controller\CardPut();
//        $ComBonus = new Bonus();
//        //查询领卡记录
//        $user = $CardUserGet->where('id', $updata['get_card_id'])->find();
////        return $user;
//        //余额更新
//        $arr['card_id'] = $user['card_id'];
//        $arr['code'] = $user['code'];
//        $arr['openid'] = $updata['openid'];
//        $arr['mid'] = $updata['mid'];
//        $arr['giveid'] = $CardCzLog->where('orderid', $updata['orderid'])->value('giveid');
//        $arr['add_balance'] = $updata['price'];
//        $arr['id'] = $user['id'];
//        $arr['nickname'] = 'ONLINERECH';
//        //余额更新
//        $arrc = $ComCardPut->checkgive($arr);
//        //变动更新
//        $re = $CardUserGet->where('id', $user['id'])->setInc('balance', $arrc['add_balance']);
//        if ($re !== false) {
//            if ($arr['giveid'] !== ''){
//                $user['giveid'] = $arr['giveid'];
//                $resb = $ComBonus->cs_bonus_rec($user);
//            }else{
//                $resb = $ComBonus->cz_bonus_rec($user,$arr);
//            }
//            //余额变动模版消息
//            $balance = $CardUserGet->where(array('id' => $user['id']))->value('balance');
//            $spa['card_id']=$user['card_id'];
//            $spa['openid']=$user['openid'];
//            $spa['add_balance']= $arrc['add_balance'];
//            $spa['balance']=$balance;
//            $spa['type']=1;
//            $wxMsg = new TemplateMsg();
//            $wxMsg->send_tpl('pay_balance', $spa);
//            //保存变动记录
//            $arr['hx_fs']=4;
//            $arr['type']=1;
//            $arr['cate']=2;
//            $arr['reason']=3;
//            $arr['source']=1;
//            $arr['add_bonus'] = $resb['add_bonus'];
//            $updataid = $ComBalance->cardupdate($arr, $user, $arrc);
//            //订单记录
//            $arr['pay_balance'] = $arrc['pay_balance'];
//            $datalog = $ComBalance->paylog_rec($arr);
//            //充值记录
//            $give_rec_id = $ComBalance->cardczlog_rec($datalog, $user, $arrc, $arr);
//            //冲送
//            $arr['give_rec_id'] = $give_rec_id;
//            $arr['top_mid'] = $user['top_mid'];
//            $arr['updataid'] = $updataid;
//            $resut = $ComBalance->cs_type($arr, $user);
//            return $resut;
//        }
//
//    }
//
//    public function inc_bonus()
//    {
//        if (Request()->isAjax()) {
//            $arr = request()->post();
//            $ComBonus = new Bonus();
//            $arr['record_bonus'] = '';
//            $arr['bonus'] = $arr['add_bonus'];
//            $arr['hx_fs'] = 4;
//            $arr['type'] = 1;
//            $arr['cate'] = 1;
//            $arr['reason'] = 3;
//            $arr['source'] = 1;
//            $res = $ComBonus->add_bonus_rec($arr);
//            return json($res);
//        }
//    }
//
//    public function hx_bonus()
//    {
//        if (Request()->isAjax()) {
//            $arr = request()->post();
//            $ComBonus = new Bonus();
//            $arr['record_bonus']='';
//            $arr['hx_fs']=4;
//            $arr['type']=2;
//            $arr['cate']=1;
//            $arr['reason']=3;
//            $arr['source']=1;
//            $res = $ComBonus->hx_bonus_del($arr);
//            return $res;
//        }
//    }
//
//
//    //
//    public function testblance(){
//        $arr['code'] = '047216868697';
//        $arr['card_id'] = 'pomWzjkI2Py-KWVNSYgKRng3lfgk';
//        $arr['price'] = 34.4;
//        $Balancet = new Balance();
//        $res = $Balancet->updatebalance($arr);
//        var_dump($res);
//    }
//
//
//    public function getusercardus(){
//        $card_id = 'pAldkw907QzSqht75Sb98Obh3eW8';
//        $data['card_id'] = $card_id;
//        $data['openid'] = 'oAldkw6yp8BBfRlfUrj8ylF-r9h8';
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->userGetCard($data);
//        var_dump(json_encode($res,JSON_UNESCAPED_UNICODE));
//
//    }
//
//    public function cardgx(){
//        $data['card_id'] = '';
//        $data['card_id'] = '';
//        $data['card_id'] = '';
//        $data['card_id'] = '';
//        $options = $this->options($data);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->updateUserCard($data);
//    }
//    public function getuserinfo(){
//
//        $card_id = 'pUIDrwaDYgTiBa6Hts6W1aj2YnBk';
////            $data['card_id'] = $card_id;
//        $data['openid'] = 'oUIDrwdkXGomxjxuzNdHimejSs5k';
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->getUserInfo($data['openid']);
//        var_dump(json_encode($res,JSON_UNESCAPED_UNICODE));
//
//    }
////
////    //会员卡状态检查
//    public function getusercode(Request $request){
//
//        $data['code'] = $request->param('code');
//        $CardUserGet = new CardUserGet();
//        $data['card_id'] =$CardUserGet->where(['code'=>$data['code']])->value('card_id');
//        //初始化微信API
//        $options = $this->options($data['card_id']);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->userGetInfo($data);
//        var_dump(json_encode($res,JSON_UNESCAPED_UNICODE));
////        $CardUserBonus = new CardUserBonus();
////        $list = $CardUserBonus->where($data)->select();
////        return json($list);
//    }
//
//    //设置卡券核销状态
//    public function getcardstatu(){
//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $data['card_id'] = $card_id;
//        $data['code'] = '590042425069';
//        $data['check_consume'] = true;
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->getCardState($data);
//        var_dump(json_encode($res,JSON_UNESCAPED_UNICODE));
//
//
//    }
//
//    public function fireuser(){
//        $CardUserGet = new CardUserGet();
//        $map['bonus'] = ['gt',0];
//        $map['fire'] = 0;
//        $map['card_type'] = 'MEMBER_CARD';
//        $list = $CardUserGet->where($map)->field('code,card_id,openid,id,bonus')->limit(500,50)->select();
//        $notuser = [];
//        foreach ($list as$k=>$v){
//            $opns = $this->options($v['card_id']);
//            $data['card_id'] = $v['card_id'];
//            $data['code'] = $v['code'];
//            $WxObj = new Wxobjopen($opns);
//            $res = $WxObj->userGetInfo($data);
//            if ($res['has_active'] == 'true'){
//                $notuser[$v['id']] = $data;
//            }
//        }
//        return json($notuser);
//
//    }
//
//    public function fireuserlog(){
//        $CardUserUpdate = new CardUserUpdate();
//        $map['create_time'] = [['gt',1536916393],['lt',1537153020]];
////        $map['create_time'] = ['lt',1537153020];
//        $map['type'] = 6;
////        $map['card_type'] = 'MEMBER_CARD';
//        $list = $CardUserUpdate->where($map)->field('code,card_id,openid,id')->select();
////        $sum = $CardUserUpdate->where($map)->count('id');
////        halt($sum);
//        $notuser = [];
//        $i = 0;
//        foreach ($list as$k=>$v){
//            $opns = $this->options($v['card_id']);
//            $data['card_id'] = $v['card_id'];
//            $data['code'] = $v['code'];
//            $WxObj = new Wxobjopen($opns);
//            $res = $WxObj->userGetInfo($data);
////            if ($res['has_active'] !== 'true'){
//            $notuser[$i]['res'] = $res;
//            $notuser[$i]['code'] =  $v['code'];
////            }
//            $i = $i+1;
//        }
//        var_dump(count($notuser));
//        return json($notuser);
//
//    }
//
//    public function recfireuser(Request $request){
//        $CardUserUpdate = new CardUserUpdate();
//
//
//        $map['code'] = $request->param('code');
////        $map['code'] = '667252917534';
//        if ( $request->param('type') == 1) {
//            $map['create_time'] = [['gt', 1536916393], ['lt', 1537153020]];
//            $map['type'] = 6;
//        }
//        $list = $CardUserUpdate->where($map)->field('id,mid,openid,hx_fs,code,card_id,source,record_bonus,con_username,reason,orderid,add_bonus,create_time')->select();
//        $Merchant = new  Merchant();
//        $Paylog = new Paylog();
//        $CardMember = new CardMember();
//        $CardUserGet = new CardUserGet();
//        $i = 0;
//        foreach ($list as $k=>$v){
////            $result = $this->validate(
////                $v,
////                [
////                    'orderid'  => 'unique:CardUserBonus',
////                ]);
////            if(true !== $result) {
//            $top_mid = $Merchant->where('id', $v['mid'])->value('top_mid');
//            $oid = $Paylog->where('orderid', $v['orderid'])->value('id');
//            $c_id = $CardMember->where('card_id', $v['card_id'])->value('id');
//            $us = $CardUserGet->where(['card_id' => $v['card_id'], 'code' => $v['code']])->field('id,openid')->find();
//            $data[$i]['up_id'] = $v['id'];
//            $data[$i]['mid'] = $v['mid'];
//            $data[$i]['top_mid'] = $top_mid;
//            $data[$i]['card_id'] = $v['card_id'];
//            $data[$i]['c_id'] = $c_id;
//            $data[$i]['us_id'] = $us['id'];
//            $data[$i]['openid'] = $us['openid'] == '' ? $v['openid'] : $us['openid'];
//            $data[$i]['code'] = $v['code'];
//            $data[$i]['orderid'] = $v['orderid'];
//            $data[$i]['oid'] = $oid;
//            $data[$i]['num'] = $v['add_bonus'];
//            $data[$i]['pay_cate'] = $v['hx_fs'];
//            $data[$i]['type'] = 1;
//            $data[$i]['mode'] = 0;
//            $data[$i]['cate'] = 4;
//            $data[$i]['source'] = $v['source'];
//            $data[$i]['remark'] = $v['record_bonus'];
//            $data[$i]['action_user'] = $v['con_username'];
//            $data[$i]['create_time'] = strtotime($v['create_time']);
//            $i = $i + 1;
//            var_dump($i);
//        }
////        }
////        return json($data);
////        if ()
//        Db::name('CardUserBonus')->insertAll($data);
//
//    }
//
//
//    public function recfireusers(Request $request){
//        $CardUserUpdate = new CardUserUpdate();
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
//
//        $map['code'] = $request->param('code');
//
//        $user['xy'] = $CardUserGet->where($map)->value('bonus');
//
//        $user['ls'] = $CardUserBonus->where($map)->sum('num');
//        $user['lsc'] = $CardUserBonus->where($map)->count('id');
//        halt($user);
////        $map['code'] = '667252917534';
//        if ( $request->param('type') == 1) {
//            $map['create_time'] = [['gt', 1536916393], ['lt', 1537153020]];
//            $map['type'] = 6;
//        }
//        $list = $CardUserUpdate->where($map)->field('id,mid,openid,hx_fs,code,card_id,source,record_bonus,con_username,reason,orderid,add_bonus,create_time')->select();
//        $Merchant = new  Merchant();
//        $Paylog = new Paylog();
//        $CardMember = new CardMember();
//
//
//        $i = 0;
//        foreach ($list as $k=>$v){
//            $mab['card_id'] = $v['card_id'];
//            $mab['code'] = $v['code'];
//            $mab['type'] = 1;
//            $bonuss = $CardUserBonus->where($mab)->sum('num');
//            $mac['card_id'] = $v['card_id'];
//            $mac['code'] = $v['code'];
//            $user = $CardUserGet->where($mac)->value('bonus');
//            if ($user > $bonuss){
//                $us[] = $mac;
//            }
//            echo '1:'.$bonuss;
//            echo '---';
//            echo '2:'.$user;
//            echo '</br>';
//
////            $result = $this->validate(
////                $v,
////                [
////                    'orderid'  => 'unique:CardUserBonus',
////                ]);
////            if(true !== $result) {
////            $top_mid = $Merchant->where('id', $v['mid'])->value('top_mid');
////            $oid = $Paylog->where('orderid', $v['orderid'])->value('id');
////            $c_id = $CardMember->where('card_id', $v['card_id'])->value('id');
////            $us = $CardUserGet->where(['card_id' => $v['card_id'], 'code' => $v['code']])->field('id,openid')->find();
////            $data[$i]['up_id'] = $v['id'];
////            $data[$i]['mid'] = $v['mid'];
////            $data[$i]['top_mid'] = $top_mid;
////            $data[$i]['card_id'] = $v['card_id'];
////            $data[$i]['c_id'] = $c_id;
////            $data[$i]['us_id'] = $us['id'];
////            $data[$i]['openid'] = $us['openid'] == '' ? $v['openid'] : $us['openid'];
////            $data[$i]['code'] = $v['code'];
////            $data[$i]['orderid'] = $v['orderid'];
////            $data[$i]['oid'] = $oid;
////            $data[$i]['num'] = $v['add_bonus'];
////            $data[$i]['pay_cate'] = $v['hx_fs'];
////            $data[$i]['type'] = 1;
////            $data[$i]['mode'] = 0;
////            $data[$i]['cate'] = 4;
////            $data[$i]['source'] = $v['source'];
////            $data[$i]['remark'] = $v['record_bonus'];
////            $data[$i]['action_user'] = $v['con_username'];
////            $data[$i]['create_time'] = strtotime($v['create_time']);
////            $i = $i + 1;
////            var_dump($i);
//        }
////        return json($us);
////        }
////        return json($data);
////        if ()
////        Db::name('CardUserBonus')->insertAll($data);
//
//    }
//
//    public function testpayment(){
//        $arr['mid'] = '501';
//        $arr['orderid'] = 'H501-2018071411041248164';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $arr['price'] = '0.02';
//        $arr['add_time'] = '1531537452';
//        $res = $this->pay_card_put($arr);
//        var_dump($res);
//    }
//
//
//    public function cardfiretype(){
//        $map['activate'] = 1;
//        $CardMember = new CardMember();
//        $CardUserUpdate = new CardUserUpdate();
//        $CardUserBonus = new CardUserBonus();
//        $list = $CardMember->where($map)->field('card_id')->select();
//        foreach ($list as $k=>$v){
//            $cardlist[] = $v['card_id'];
//        }
//        $mab['card_id'] = ['in',$cardlist];
//        $mab['create_time'] = [['gt',1536915901],['lt',1537253820]];
//        $mab['con_username'] = 'FIREGIFT';
//
//        $up['sum'] = $CardUserUpdate->where($mab)->count('id');
//        $up['data'] = $CardUserUpdate->where($mab)->field('card_id,code,openid,add_bonus,create_time,mid')->select();
//        $up['sql'] = $CardUserUpdate->getLastSql();
//
////       var_dump($up['sum']);
//
////       var_dump($CardUserUpdate->getLastSql());
//        $Mechant = new Merchant();
//        $CardUserGet = new CardUserGet();
//        $i = 0;
//        foreach ($up['data'] as $k=>$v) {
////            $code[]  = $v['code'];
//            $code[$i]['mid'] = $v['mid'];                                                                   //1
//            $code[$i]['top_mid'] = $Mechant->where(['id'=>$v['mid']])->value('top_mid');              //2
//            $code[$i]['c_id'] = $CardMember->where(['card_id'=>$v['card_id']])->value('id');          //3
//            $code[$i]['us_id'] = $CardUserGet->where(['code'=>$v['code']])->value('id');              //4
//            $code[$i]['code'] = $v['code'];                                                                 //5
//            $code[$i]['openid'] = $v['openid'];                                                             //6
//            $code[$i]['num'] = $v['add_bonus'];                                                             //7
//            $code[$i]['card_id'] = $v['card_id'];                                                           //8
//            $code[$i]['pay_cate'] = 25;                                                                     //9
//            $code[$i]['type'] = 1;                                                                          //10
//            $code[$i]['mode'] = 0;                                                                          //11
//            $code[$i]['cate'] = 5;                                                                          //12
//            $code[$i]['source'] = 'online';                                                                 //13
//            $code[$i]['remark'] = '激活赠送';                                                                //14
//            $code[$i]['action_user'] = 'FIREGIFT';                                                          //15
//            $code[$i]['create_time'] = strtotime($v['create_time']);                                        //16
//            $i = $i+1;
//        }
////        var_dump(count($code));
////        return json($code);
////        $bonus['sum'] = count($code);
////        $bonus['data'] = $code;
//        $res = Db::name('CardUserBonus')->insertAll($code);
//        return json($res);
//
////        $mac['code'] = ['in',$code];
////        $mac['action_user'] = 'FIREGIFT';
////        $bon['sum']= $CardUserBonus->where($mac)->count('id');
////        $bon['data'] = $CardUserBonus->where($mac)->select();
////        $bon['sql'] = $CardUserBonus->getLastSql();
//
////
////        unset( $up['data']);
////        var_dump(json_encode($up,JSON_UNESCAPED_UNICODE));
////        return json($bon);
////        var_dump(json($bon));
////       return json($up);
//    }
//
//    //补充已激活用户的积分记录
//    public function recfireuserbonus(){
//        $data = '{
//	"276001": {
//		"card_id": "p9m68wV78KYhaOmGxIIwryJdCubY",
//		"code": "466562443137"
//	},
//	"276007": {
//		"card_id": "pgwQKwf60Yom1pJbZ_J08LYJnFkg",
//		"code": "131752488431"
//	},
//	"283913": {
//		"card_id": "poNOts30YUVlmVKdihSrDsRqrDqI",
//		"code": "175479597304"
//	},
//	"283928": {
//		"card_id": "pUIDrwaDYgTiBa6Hts6W1aj2YnBk",
//		"code": "690564492952"
//	},
//	"284027": {
//		"card_id": "pgwQKwf60Yom1pJbZ_J08LYJnFkg",
//		"code": "401368001701"
//	},
//	"284099": {
//		"card_id": "pVPrBjt54SC1Oj_bc1dsCQiMNtW8",
//		"code": "082716766945"
//	},
//	"284118": {
//		"card_id": "p-eGQwWf6wOE0N1HEPNCWAGamNEw",
//		"code": "452532038835"
//	},
//	"284140": {
//		"card_id": "pDhOHjgdUWpviqPB2HXGxi9osaNY",
//		"code": "736669904862"
//	},
//	"284185": {
//		"card_id": "pVPrBjt54SC1Oj_bc1dsCQiMNtW8",
//		"code": "381478009056"
//	}
//}';
//        $data = json_decode($data,true);
//        foreach ($data as $k => $v){
//            $code[] = $v['code'];
//        }
//        $map['code'] = ['in',$code];
//        $CardUserGet = new CardUserGet();
//        $Wxcard = new Wxcard();
//        $Momerchant = new Momerchant();
//        $WxOpen = new WxOpen();
//        $list = $CardUserGet->where($map)->field('top_mid,id,code,openid,card_id,fire,bonus,balance,fire_time,create_time')->select();
//
//        foreach ($list as $k=>$v){
//            $wx_open_id = $Momerchant->where('id',$v['top_mid'])->value('wx_open_id');
//            $datas['cardid'] = $v['card_id'];
//            $datas['openid'] = $v['openid'];
//            $datas['usercardcode'] = $v['code'];
//            $datas['gh_id'] = $WxOpen->where('id',$wx_open_id)->value('gh_id');
//
//            $res[$v['code']] = action('index/wxcard/userfirecard',[$datas]);
//        }
//        return json($res);
//
//
//    }
//
//
//    //删除未激活会员的积分记录和激活前产生的记录
//    public function deluserfirebonus(){
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
////        $map['create_time'] = ['gt',1535731200];
//        $map['card_id'] = 'ponDvvznUE0amrjPwvMFX-nmKix8';
//        $map['fire'] = 1;
//        $num = $CardUserGet->where($map)->count('id');
////        return json($num);
//        $userli = $CardUserGet->where($map)->field('id,code,bonus,card_id,fire_time,fire')->select();
//
//        foreach ($userli as $k=>$v){
//            $code[] = $v['code'];
//
//        }
//        $mab['code'] = ['in',$code];
//        $num = $CardUserBonus->where($mab)->count();
////        $num = $CardUserBonus->where($mab)->delete();
//        return json($num);
////        $userli['zsnum'] = $CardUserGet->where($map)->count('id');
////        $userli['sql'] = $CardUserGet->getLastSql();
//        return json($notuser);
//    }
//
//    //查询积分记录和用户记录
//    public function jcuserbonus(){
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
////        $map['create_time'] = ['gt',1535731200];
//        $map['card_id'] = 'ponDvvznUE0amrjPwvMFX-nmKix8';
//        $map['fire'] = 1;
////        $num = $CardUserGet->where($map)->count('id');
////        return json($num);
//        $userli = $CardUserGet->where($map)->field('id,code,bonus,card_id,fire_time,fire')->limit(0,1000)->select();
//
//        foreach ($userli as $k=>$v){
//            $code[$k][$v['id']]['num'] = $CardUserBonus->where('code',$v['code'])->count('id');
//
//        }
////        $mab['code'] = ['in',$code];
////        $num = $CardUserBonus->where($mab)->count();
////        $num = $CardUserBonus->where($mab)->delete();
//        return json($code);
////        $userli['zsnum'] = $CardUserGet->where($map)->count('id');
////        $userli['sql'] = $CardUserGet->getLastSql();
//    }
//
//    //积分对比
//    public function bonusis(Request $request){
//
//
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
//        if ($request->post()) {
//            $param = $request->post();
//            $map['create_time'] = ['lt',1535731200];
//            $map['card_type'] = 'MEMBER_CARD';
//            $map['fire'] = 0;
//            $userli = $CardUserGet->where($map)->field('code,bonus')->limit($param['ks'], $param['end'])->select();
////        foreach ($userli as $k=>$v){
////            $code[] = $v['code'];
////        }
////        $mab['code'] = ['not in',$code];
////        $mab['card_id'] = 'ponDvvznUE0amrjPwvMFX-nmKix8';
////        $asd = $CardUserBonus->where($mab)->sum('num');
//////        var_dump($CardUserBonus->getLastSql());
////        halt($asd);
//            foreach ($userli as $k => $v) {
//                $code[$k]['code'] = $v['code'];
//                $code[$k]['bonus'] = $v['bonus'];
//                $mab['code'] = $v['code'];
//                $mab['type'] = ['neq', 2];
//                $yy_bonus = $CardUserBonus->where($mab)->sum('num');
//                $code[$k]['yy_bonus'] = $yy_bonus;
//                $bonus = $v['bonus'];
//                if (abs($yy_bonus) > abs($bonus)) {
//                    var_dump(json_encode($v['code'], JSON_UNESCAPED_UNICODE));
//                }
//            }
//        }else{
//            return $this->fetch();
//        }
//    }
//
//    //查询积分总量
//    public function bonususer(){
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
////        $map['card_id'] = 'ponDvvznUE0amrjPwvMFX-nmKix8';
////        $map['top_mid'] = ['neq',1];
//        $map['card_type'] = 'MEMBER_CARD';
//        $user['user'] = $CardUserGet->where($map)->sum('bonus');
////        $mab['card_id'] = 'ponDvvznUE0amrjPwvMFX-nmKix8';
////        $mab['top_mid'] = ['neq',1];
//        $mab['type'] = ['neq',2];
//        $user['add_bonus'] = $CardUserBonus->where($mab)->sum('num');
//
////        $mac['top_mid'] = ['neq',1];
//        $mac['type'] = 2;
//        $user['del_bonus'] = $CardUserBonus->where($mac)->sum('num');
//
//        $user['sy_bonus'] = $user['add_bonus']-$user['user'];
//        return json($user);
//    }
//
//
//    //批量查询掉卡会员（未激活）   9-1之后
//    public function cxdk(){
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
////        $map['create_time'] = ['gt',1537488000];
//        $map['card_id'] = 'pFQIP1Ja9oMHQf_E1WhJolt_D50E';
//        $map['fire'] = 0;
//        $userli = $CardUserGet->where($map)->field('id,code,bonus,card_id,fire_time,fire,openid')->select();
//        $notuser = 1;
//        $Wxcard = new Wxcard();
//        foreach ($userli as $k=>$v){
//            $open = $this->options($v['card_id']);
//            $wxObj = new Wxobjopen($open);
//            $data['card_id'] = $v['card_id'];
//            $data['code'] = $v['code'];
//            $res = $wxObj->userGetInfo($data);
//            if ($res['errcode'] == 0) {
//                if ($res['has_active'] == 'true') {
//                    $sql['usercardcode'] = $data['code'];
//                    $sql['cardid'] = $data['card_id'];
//                    $sql['openid'] = $v['openid'];
//                    $res['1'] = $Wxcard->userfirecard($sql);
////                    $res = $CardUserGet->save(['fire'=>1],$data);
//                    var_dump($res);
//                }else{
////                    $notuser = 2;
//                    var_dump(2);
//                }
//            }else{
////                $notuser[$v['id']] = $res;
//                var_dump($res);
//            }
//
//        }
//        return json($notuser);
//    }
//
//    //批量查询掉卡会员（未激活）   9-1之前
//    public function xcdks(Request $request){
//        $CardUserGet = new CardUserGet();
//        $CardUserBonus = new CardUserBonus();
//        if ($request->isPost()) {
//            Debug::remark('begin');
//            $param = $request->post();
//            $map['card_type'] = 'MEMBER_CARD';
////            $map['fire'] = 1;
////            $map['top_mid'] = ['neq',1];
//            $userli = $CardUserGet->where($map)->field('card_id,top_mid,openid,code,bonus')->limit($param['ks'], $param['end'])->select();
//            foreach ($userli as $k => $v) {
//                $code[$k]['code'] = $v['code'];
//                $code[$k]['bonus'] = $v['bonus'];
//                $code[$k]['card_id'] = $v['card_id'];
//                $code[$k]['top_mid'] = $v['top_mid'];
//                $code[$k]['openid'] = $v['openid'];
//                $code[$k]['num'] = 6;
//                //END
//                $mab['code'] = $v['code'];
//                $mab['type'] = ['neq', 2];
//                $bonus = $v['bonus'];
//                $add_bonus = $CardUserBonus->where($mab)->sum('num');
//                $mac['code'] = $v['code'];
//                $mac['type'] = 2;
//
//                $del_bonus = $CardUserBonus->where($mac)->sum('num');
//                $yy_bonus = $add_bonus - $del_bonus;
//                //END
//                $code[$k]['yy_bonus'] = $yy_bonus;
//                if ($yy_bonus > abs($bonus)) {
//                    $code[$k]['type'] = 21;     //
//                } elseif ($yy_bonus < 0) {
//                    $code[$k]['type'] = 22;
//                } elseif($yy_bonus == abs($bonus)){
//                    $code[$k]['type'] = 20;
//                }else{
//                    $code[$k]['type'] = 23;
//                }
//
//            }
//            Db::name('CardUserMiss')->insertAll($code);
//            //
////            $map['type'] = 0;
////            $codeli = Db::name('CardUserMiss')->where($map)->limit($param['ks'], $param['end'])->field('code')->select();
////            foreach ($codeli as $k=>$v){
////                $code[] = $v['code'];
////            }
////            $map['code'] = ['in',$code];
////            $CardUserBonus = new CardUserBonus();
////            $bon['1'] = $CardUserBonus->where($map)->count();
////            $bon['2'] = $CardUserBonus->where($map)->sum('num');
//
////            $map['create_time'] = ['lt',1535731200];
////            $map['card_type'] = 'MEMBER_CARD';
////
////            $map['fire'] = 0;
////            $userli = $CardUserGet->where($map)->field('id,code,card_id,openid')->limit($param['ks'], $param['end'])->select();
//            //END
//////            file_put_contents('/data2/html/payos/xcdks.txt', '1:' . json_encode($open, JSON_UNESCAPED_UNICODE), FILE_APPEND);
////            foreach ($userli as $k => $v) {
////                $open = $this->options( $v['card_id']);
////                $wxObj = new Wxobjopen($open);
////                $data['card_id'] = $v['card_id'];
////                $data['code'] = $v['code'];
////                $res = $wxObj->userGetInfo($data);
////                if ($res['errcode'] == 0) {
////                    if ($res['has_active'] == 'true') {
////                        $datas = $data;
////                        $datas['type'] = 1;
////                        $datas['openid'] =  $v['openid'];
////                        $notuser['miss'][$v['id']] = $datas;
////                    }else{
////                        $datas = $data;
////                        $datas['type'] = 0;
////                        $datas['openid'] =  $v['openid'];
////                        $notuser['not'][$v['id']]= $datas;
////                    }
////                }else{
////                    $datas = $data;
////                    $res['type'] = 2;
////                    $datas['openid'] =  $v['openid'];
////                    $datas['remark'] = json_encode($res,JSON_UNESCAPED_UNICODE);
////                    $notuser['error'][$v['id']]= $datas;
////                }
////            }
////            if (isset($notuser['miss'])) {
////                Db::name('CardUserMiss')->insertAll($notuser['miss']);
////            }else{
////                $notuser['miss'] = [];
////            }
////            if (isset($notuser['not'])) {
////                Db::name('CardUserMiss')->insertAll($notuser['not']);
////            }else{
////                $notuser['not'] = [];
////            }
////            if (isset($notuser['error'])) {
////                Db::name('CardUserMiss')->insertAll($notuser['error']);
////            }else{
////                $notuser['error'] = [];
////            }
//            //END
//
//            Debug::remark('end');
//            echo Debug::getRangeTime('begin', 'end') . 's';
//            echo "</br>";
////            var_dump($bon);
////            $miss = count($notuser['miss']);
////            $not = count($notuser['not']);
////            $error = count($notuser['error']);
////            echo $miss.'-'.$not.'-'.$error;
//        }
//        $param = $request->param();
//        if (isset($param['ks']) && $param['end']) {
//            $arrss['ks'] = $param['ks'] + $param['end'];
//            $arrss['end'] = $param['end'];
//        } else {
//            $arrss['ks'] = 0;
//            $arrss['end'] = 1000;
//        }
//        $this->assign('info', $arrss);
//        return $this->fetch('cxdks');
//
//    }
//
//
//
//
//    public function qweqwe(){
//        $s['start_time'] = strtotime("last month");
//        $s['end_time'] = time();
//        var_dump($s);
//    }
//
//    public function qwe_paycardpay(){
//        $orderid = 'H722-2018092210332742595';
//        $id = Db::name('Paylog')->where(['orderid'=>$orderid])->field('mid,sub_openid,orderid,cz_card_id')->find();
//        $updata['mid'] = $id['mid'];
//        $updata['openid'] = $id['sub_openid'];
//        $updata['orderid'] = $id['orderid'];
//        $updata['get_card_id'] = $id['cz_card_id'];
//        $res = action('index/wxpay/pay_card_put_nu',[$updata]);
//        halt($res);
//    }
//
//    public function order_query(Request $request){
//        $orderid = $request->param('orderid');
//        $Paylog = new Paylog();
//        $mab['orderid'] = $orderid;
//        $id = $Paylog->where($mab)->find();
//        $Merchant = new Merchant();
//        $Agent = new Agent();
//        $WxOpen = new WxOpen();
//        $map['id'] = $id['mid'];
//        $config = $Merchant->where($map)->find();
//        $agent = $Agent->where(array('id' => $config['agent']))->find();
//        $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
//        $userwx = $WxOpen->where(array('id' => $config['wx_open_id']))->find();
//
//        $options = array(
//            'appid' => $users['authorizer_appid'], // 填写高级调用功能的app id
//            'partnerid' => $agent['partnerid'], // 财付通商户身份标识
//            'partnerkey' => $agent['partnerkey'], // 财付通商户权限密钥Key
//        );
//
//        $weObj = new Wxobjopen($options);
//        $appid = $users['authorizer_appid'];
//        $mch_id = $agent['partnerid'];
//        $out_trade_no = $orderid;
//        $nonce_str = $weObj->generateNonceStr();
//        $sub_mch_id = $config['sub_mch_id'];
//        $sub_appid = $userwx['authorizer_appid'];
//        $pay_xml = $weObj->createOrderXml($appid, $mch_id, $sub_appid, $sub_mch_id, $out_trade_no, $nonce_str);
//        $payorder_xml = $weObj->getPayNum($pay_xml);
//        halt($payorder_xml);
//    }
//
//
//
//    public function userlist(Request $request){
//        $param = $request->param();
//        $map['c_id'] = 0;
//        $CardUserGet = new CardUserGet();
//        if ($param['type'] == 1) {
//
//            $sum = $CardUserGet->where($map)->count();
//            halt($sum);
//        }else {
////            $total = $CardUserGet->alias('a')->join('wn_card_member b', 'b.card_id=a.card_id', 'left')
////                ->where($map)->field('a.id,b.id as c_id')->limit(0, 5000)->select();
////            foreach ($total as $k => $v) {
////                if ($v['c_id'] !== '') {
////                    $data[$k]['id'] = (int)$v['id'];
////                    $data[$k]['c_id'] = $v['c_id'];
////                } else {
////                    $data[$k]['id'] = (int)$v['id'];
////                    $data[$k]['c_id'] = 1;
////                }
////            }
//            $data['c_id'] = 0;
//            $map['c_id'] = null;
//            $res = $CardUserGet->save($data,$map);
////        return json($total);
//            halt($res);
//        }
//
//    }

//
//    public function baobiao(){
//        //top_mid
//        $Momerchant=new Momerchant();
//
////        $machlist=$Momerchant->field('id')->select();
//        $machlist = $Momerchant->where(['id'=>1])->field('id')->select();
//        //用户列表
//        foreach($machlist as $ks=>$vs){
//            $arr['top_mid']=$vs['id'];
//            $userlist = $this->getsendren($arr);
//
//            //获取统计，组合数据
//            foreach ($userlist as $k=>$v){
//                $arrq['mid'] = $v['mid'];
//                $balance = $this->conutbalance($arrq);        //余额统计
//
//                $cards = $this->conutcards($arrq);            //卡券统计
//
//                $cardus = $this->conutcardus($arrq);         //会员卡统计
//
//                $cash = $this->cashPay($arrq);         //会员卡统计
//
//                $pay = $this->conutpay($arrq);               //支付统计
//
//                $sum = $this->sum_data($pay,$cash);
//
//                //组合数据
//                $data['openid'] = $v['openid'];
//                $data['mid'] = $arrq['mid'];
//                $data['top_mid'] = $arr['top_mid'];
//                $data['keyword1'] = date("Y-m-d", time() - 86399) .'日统计报告';
//                $data['remark'] =
//                    "微信支付:".$pay['wx_pay_freq'].'笔 / '.$pay['wx_pay_sum']."元\n".
//                    "支付宝支付:".$pay['ali_pay_freq']."笔 / ".$pay['ali_pay_sum']."元\n".
//                    "现金支付:".$cash['pay_freq']."笔 / ".$cash['pay_sum']."元\n".
//                    "收款总计:".$sum['pay_freq']."笔 / ".$sum['pay_price']."元\n".
//                    "会员卡支付总计:".$balance['pay_freq']."笔 / ".$balance['pay_sum']."元\n".
//                    "-------------------------\n".
//                    "当日会员:"."新增".$cardus['get_freq']."人 / "."总计".$cardus['sum_freq']."人\n".
//                    "当日卡券:"."领取".$cards['get_freq']."人 / "."核销".$cards['con_freq']."人\n";
//
//                $res = $this->sendtpl($data);
//                return json($res);
//            }
//        }
//    }
//
////    public function getydh(){
////        $Ydh = new Ydhwork();
////
////    }
//
//    //总计
//    private function sum_data($pay,$balance){
//        $sum['pay_freq'] = $pay['wx_pay_freq'] + $pay['ali_pay_freq'] + $balance['pay_freq'];        //笔数
//        $sum['pay_price'] = $pay['wx_pay_sum'] + $pay['ali_pay_sum'] + $balance['pay_sum'];        //金额
//        return $sum;
//    }
//
//    //余额统计
//    private function conutbalance($arr){
//        $Paylog = new Paylog();
//        //条件
//        $today = strtotime(date("Y-m-d"),time()) - 86400;
//        $enday = $today + 86399;
//
//        //储值
////        $mab['create_time'] = ['between',[$today,$enday]];
////        $mab['mid'] = ['in',$arr['mid']];;
////        $mab['add_balance'] = ['neq','0'];
////        $mab['type'] = 1;
////        $arr['pay_freq_cz'] = $CardUserUpdate->where($mab)->count('id');                  //储值次数
////        $arr['pay_balance'] = $CardUserUpdate->where($mab)->sum('pay_balance');        //支付余额
////        $arr['add_balance'] = $CardUserUpdate->where($mab)->sum('add_balance');        //增加余额
//
//        //消费
//        $mad['add_time'] = ['between',[$today,$enday]];
//        $mad['mid'] = ['in',$arr['mid']];
////        $mad['del_balance'] = ['neq','0'];
//        $mad['pay_fs'] = 8;
//        $arr['pay_freq'] = $Paylog->where($mad)->select('id');                  //消费次数
//        $arr['pay_sum'] = $Paylog->where($mad)->sum('price');        //消费余额
//        return $arr;
//    }
//
//    //现金统计
//    public function cashPay($arr){
//        $Paylog = new Paylog();
//        //条件
//        $today = strtotime(date("Y-m-d"),time()) - 86400;        //开始
//        $enday = $today + 86399;        //结束
//        //现金查询
//        $mab['add_time'] = ['between',[$today,$enday]];        //时间
//        $mab['mid'] = ['in',$arr['mid']];
//        $mab['pay_fs'] = 4;
//        $mab['pay_statu'] = 1;
//        $arr['pay_freq'] = $Paylog->where($mab)->count();    //现金支付次数
//        $arr['pay_sum'] = $Paylog->where($mab)->sum('price');     //现金支付金额
//        return $arr;
//    }
//
//    //卡券统计
//    private function conutcards($arr){
//        $CardUserGet = new CardUserGet();
//        $CardConsume = new CardConsume();
//        //条件
//        $today = strtotime(date("Y-m-d"),time()) - 86400;
//        $enday = $today + 86399;
//        $map['create_time'] = ['between',[$today,$enday]];
//        $map['card_type'] = ['neq','MEMBER_CARD'];
//        $map['mid'] = ['in',$arr['mid']];
//        //统计
//        //核销
//        $mab['create_time'] = ['between',[$today,$enday]];
////        $mab['card_type'] = ['neq','MEMBER_CARD'];
//        $mab['mid'] = ['in',$arr['mid']];
//        $arr['get_freq'] = $CardUserGet->where($map)->count('id');      //领取数量
//        $arr['con_freq'] = $CardConsume->where($mab)->count('id');      //核销数量
//        return $arr;
//    }
//
//    //会员卡统计
//    public function conutcardus($arr){
//        $CardUserGet = new CardUserGet();
//        //条件
//        $today = strtotime(date("Y-m-d"),time()) - 86400;
//        $enday = $today + 86399;
//        $map['create_time'] = ['between',[$today,$enday]];
//        $map['card_type'] = ['eq','MEMBER_CARD'];
//        $map['mid'] = ['in',$arr['mid']];
//        $map['have'] = 1;
//        $arr['get_freq'] = $CardUserGet->where($map)->count('id');      //领取人数
//        $arr['fire_freq'] = $CardUserGet->where($map)->count('id');      //激活人数
//        //总数
//        $mad['card_type'] = ['eq','MEMBER_CARD'];
//        $mad['mid'] = ['in',$arr['mid']];
//        $mad['have'] = 1;
//        $arr['sum_freq'] = $CardUserGet->where($mad)->count('id');      //总数
//        //删除
//        $mab['create_time'] = ['between',[$today,$enday]];
//        $mab['card_type'] = ['eq','MEMBER_CARD'];
//        $mab['have'] = 2;
//        $mab['mid'] = ['in',$arr['mid']];
//        $arr['del_freq'] = $CardUserGet->where($mab)->count('id');      //删除人数
//        return $arr;
//    }
//
//    //支付统计
//    private function conutpay($arr){
//        $Paylog = new Paylog();
//        //条件
//        $today = strtotime(date("Y-m-d"),time()) - 86400;
//        $enday = $today + 86399;
//        //微信查询
//        $map['add_time'] = ['between',[$today,$enday]];        //时间
//        $map['mid'] = ['in',$arr['mid']];
//        $map['pay_fs'] = ['in',[0,2]];
//        $map['pay_statu'] = 1;
//        $arr['wx_pay_freq'] = $Paylog->where($map)->count('mid');    //微信支付次数
//        $arr['wx_pay_sum'] = $Paylog->where($map)->sum('price');     //微信支付金额
//        //支付宝查询
//        $mab['add_time'] = ['between',[$today,$enday]];        //时间
//        $mab['mid'] = ['in',$arr['mid']];
//        $mab['pay_fs'] = ['in',[1,3]];
//        $mab['pay_statu'] = 1;
//        $arr['ali_pay_freq'] = $Paylog->where($mab)->count('mid');    //微信支付次数
//        $arr['ali_pay_sum'] = $Paylog->where($mab)->sum('price');     //微信支付金额
//        return $arr;
//    }
//
//    //发送
//    private function sendtpl($data){
//        if($data){
//            $res = action('merchant/jobmach/task_tpl_stati',array($data));
//
//            return $res;
//        }
//    }
//
//    //获取发送人
//    private function getsendren($arr){
//        $LoginUsers = new LoginUsers();
//        $arrs['top_mid'] = $arr['top_mid'];
//        //店长
//        $mer_mid = $this->getstamid($arr);
//        if($mer_mid!==''){
//            $smerid = explode(',', $mer_mid);
//            $len = count($smerid);
//            if ($len > 1){
//                foreach($smerid as $k=>$v){
//                    $msid[]=array(array('like','%,'.$v),array('like',$v.',%'),array('like','%,'.$v.',%'),array('eq',$v),'or');
//                }
//                $map['mid']=array($msid,'or');
//            }else{
//                $map['mid']=$mer_mid;
//            }
//        }else{
//            $map['mid']=0;
//        }
//        $map['level'] = ['eq',3002];
//        $map['openid']=array('neq','');
//        $map['is_report'] = 1;
//        $userlist = $LoginUsers->where($map)->field('id,top_mid,mid,openid')->select();
////        $reslist = array_merge($master,$userlist);
//        $reslist = $userlist;
//        return $reslist;
//    }
//


//


//删除
//    public function delcardsgen()
//    {
//
//        $card_id = 'pCREV1s5N-vCoDfg7M3snULqnqNM';
//        $data['card_id'] = $card_id;
//        //初始化微信API
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->delUserCard($data);
//        var_dump($res);
//        if ($res['errcode'] == 0) {
//            $CardGeneral = new CardGeneral();
//            $CardGeneral->where('card_id', $card_id)->delete();
//            $CardUserGet = new CardUserGet();
//            $CardUpdate = new CardConsume();
//            $CardUpdate->where(['card_id' => $card_id])->delete();
//            $CardUserGet->where(['card_id' => $card_id])->delete();
//            halt('删除成功');
//            $this->success('删除成功', 'carus/carduslist', '', 1);
//        } else {
//            $this->error('删除失败' . $res['errmsg'], 'cardus/carduslist', '', 3);
//        }
//    }
//
//    public function getLists($type = ''){
//
////        return 1;
//        $CardUserGet = new CardUserGet();
//        $CardUserGetAli = new CardUserGetAli();
//        $Merchant = new Merchant();
//        $p_data = request()->get();
//        unset($p_data['page']);
//        $map = [];
//        if ($p_data) {
//            if ($p_data['nickname']) {
//                $map['nickname'] = array('like', '%' . trim($p_data['nickname']) . '%');
//            } else {
//                $p_data['nickname'] = '';
//            }
//            if ($p_data['code']) {
//                $map['code|phone|old_code'] = array('like', '%' . trim($p_data['code']) . '%');
//            } else {
//                $p_data['code'] = '';
//            }
//            if ($p_data['fire']) {
//                $map['fire'] = $p_data['fire'];
//            } else {
//                //激活状态
//                if (isset($p_data['fire'])){
//                    if ($p_data['fire'] == 0 && $p_data['fire'] <> ''){
//                        $map['fire'] = 0;
//                    }
//                }
//                //END
//                $p_data['fire'] = '';
//            }
//            //积分筛选
//            if ($p_data['bonus_scr']){
//                $ord['bonus'] = $p_data['bonus_scr'] ==1 ? 'desc' : 'asc';
//            }else{
//                $p_data['bonus_scr'] = '';
//
//            }
//            //余额筛选
//            if ($p_data['balance_scr']){
//                $ord['balance'] = $p_data['balance_scr'] ==1 ? 'desc' : 'asc';
//            }else{
//                $p_data['balance_scr'] = '';
//            }
//            //时间筛选
//            if ($p_data['get_scr']){
//                $ord['create_time'] = $p_data['get_scr'] ==1 ? 'asc' : 'desc';
//            }else{
//                $p_data['get_scr'] = '';
//            }
//            $ord['id'] = 'desc';
//        } else {
//            $p_data['nickname'] = '';
//            $p_data['code'] = '';
//            $p_data['fire'] = '';
//            $p_data['bonus_scr'] = '';
//            $p_data['balance_scr'] = '';
//            $p_data['get_scr'] = '';
//            $ord['id'] = 'asc';
//        }
//        $map['card_type'] = ['eq','MEMBER_CARD'];
//        $map['statu'] = 0;
//        if ($type !== ''){
//            $map['have'] = $type;
//        }else{
//            $map['have'] = 1;
//        }
//        $CardMember = new CardMember();
//        $card_id = $CardMember->where(['top_mid'=>Session::get('login_top_mid')])->value('card_id');
//        $map['card_id'] = $card_id;
//        $list = $CardUserGet->where($map)->order($ord)->paginate('20',false,['query' => request()->param()]);
//        $carduser['count'] = $CardUserGet->where(['card_id'=>$card_id])->count('id');
//        $carduser['notfire'] = $CardUserGet->where(['card_id'=>$card_id,'fire'=>0])->count('id');
//        $carduser['fire'] = $CardUserGet->where(['card_id'=>$card_id,'fire'=>1])->count('id');
//        $carduser['nothave'] = $CardUserGet->where(['card_id'=>$card_id,'have'=>0])->count('id');
//        $card['card_id'] = $card_id;
//        $card['type'] = $type;
//        $mab['id']=array('in',$this->get_mer_mid());
//        $mach = $Merchant->where($mab)->select();
//        $user = Session::get('user');
//        //充值规则
//        $CardCzgive = new CardCzgive();
//        $maps['card_id'] = $card_id;
//        $maps['statu'] = 1;
//        $czgive = $CardCzgive->where($maps)->select();
//
//        $this->assign('czgive', $czgive);
////        return 1;
//        $this->assign('carduser',$carduser);
//        $this->assign('card',$card);
//        $this->assign('p_data',$p_data);
//        $this->assign('list',$list);
//        $this->assign('mach',$mach);
//        $this->assign('user',$user);
//        return $this->fetch();
//    }
//
//
//    public function getrecharge()
//    {
//        if (Request()->isAjax()) {
//            $arr = request()->post();
//            $arr['nickname'] = '';
//            if ($arr['add_balance'] > 0 || $arr['giveid'] !== '') {
//                //数据库
//                $CardUserGet = new CardUserGet();
//                //查询
//                $user = $CardUserGet->where(array('id' => $arr['id']))->find();
//                if ($user) {
//                    $ComBalance = new Balance();
//                    $ComCardPut = new CardPut();
//                    $ComBonus = new Bonus();
//                    //余额更新
//                    $arrc = $ComCardPut->checkgive($arr);
//
//                    //变动更新
//                    $re = $CardUserGet->where('id', $user['id'])->setInc('balance', $arrc['add_balance']);
//                    if ($re !== false) {
//                        if ($arr['giveid'] !== ''){
//                            $user['giveid'] = $arr['giveid'];
//                            $resb = $ComBonus->cs_bonus_rec($user);
//                        }else{
//                            $resb = $ComBonus->cz_bonus_rec($user,$arr);
//                        }
////                        else{
////                            $resb = $ComBonus->cz_bonus_rec($user,$arr);
////                        }
//                        //余额变动模版消息
//                        $balance = $CardUserGet->where(array('id' => $user['id']))->value('balance');
//                        $spa['card_id']=$user['card_id'];
//                        $spa['openid']=$user['openid'];
//                        $spa['add_balance']= $arrc['add_balance'];
//                        $spa['balance']=$balance;
//                        $spa['type']=1;
//                        $wxMsg = new TemplateMsg();
//                        $wxMsg->send_tpl('pay_balance', $spa);
//                        //保存变动记录
//                        $arr['hx_fs']=4;
//                        $arr['type']=1;
//                        $arr['cate']=2;
//                        $arr['reason']=3;
//                        $arr['source']=1;
//                        $arr['add_bonus'] = $resb['add_bonus'];
//                        $updataid = $ComBalance->cardupdate($arr, $user, $arrc);
//                        //订单记录
//                        $arr['pay_balance'] = $arrc['pay_balance'];
//                        $datalog = $ComBalance->paylog_rec($arr);
//                        //充值记录
//                        $give_rec_id = $ComBalance->cardczlog_rec($datalog, $user, $arrc, $arr);
//                        //冲送
//                        $arr['give_rec_id'] = $give_rec_id;
//                        $arr['top_mid'] = $user['top_mid'];
//                        $arr['updataid'] = $updataid;
//                        $resut = $ComBalance->cs_type($arr, $user);
//                        //END
//                        if ($resut) {
//                            $bondata = [ 'message' => '充值成功！','code'=>0];
//                        } else {
//                            $bondata = ['code' => 9001, 'message' => '充值记录失败！'];
//                        }
//                    } else {
//                        $bondata = ['code' => 9002, 'message' => '充值失败！'];
//                    }
//                } else {
//                    $bondata = ['code' => 9003, 'message' => '请领卡后再进行充值！'];
//                }
//            } else {
//                $bondata = ['code' => 9004, 'message' => '请输入正确的充值金额！'];
//            }
//            return json($bondata);
//        }
//    }
//
//    public function testsql(){
//        $mab['mid'] = ['neq',[501]];
//        $cardu = new CardUserUpdate();
//        $sum = $cardu->where('mid','neq',501)->count('id');
//        var_dump($sum);
//    }
//
//    public function testczlist(){
//        $mab['id'] = 501;
//        $Merchant = new Merchant();
//        $map['top_mid'] = $Merchant->where($mab)->value('top_mid');
//        $map['statu'] = 1;
//        $CardCz = new CardCzgive();
//        $list = $CardCz->where($map)->select();
//        var_dump($CardCz->getLastSql());
//    }
//
//    public function getst(){
//        $card_id = 'pCVCLv0Z2UNmnrRcoC2bamHpj0EY';
//        $CardGeneral = new \app\common\model\CardGeneral();
//        $base_info = $CardGeneral->where(['card_id' => $card_id])->value('base_info');
//        $base = json_decode($base_info, true);
//        $get_sum = $base['get_limit'];
//        return $get_sum;
//
//    }
//
//    public function testorder(){
//        $map['orderid'] = 'H512-2018040610081198484';
//        $Paylog = new Paylog();
//        $CardCzlog = new CardCzLog();
//        $order = $CardCzlog->where($map)->find();
//        return json($order);
//    }
//
//    //会员卡支付
//    public function cardpay($param){
//        $CardUserGet = new CardUserGet();
//        $user = $CardUserGet->where(array('id'=>$param['id']))->field('mid,top_mid,code,card_id,balance,openid')->find();
//        if ($user['balance'] < $param['balance']){
//            return array('code'=>9001,'message'=>'余额不足');
//        }else{
//            $res = $CardUserGet->where(array('id'=>$param['id']))->setDec(array('balance'=>$param['price']));
//            $res = $CardUserGet->save(array('balance'=>0),array('id'=>$param['id']));
//            if ($res){
//                $datas['price'] = $param['price'];
//                $this->rec_paylog($datas);
//            }else{
//
//            }
//        }
//    }
//
//    private function rec_paylog($param){
//        $data['orderid'] = $this->getorder($param['mid']);
//        $data['mid'] = $param['mid'];                          //mid
//        $data['pay_statu'] = 1;                              //交易状态
//        $data['price'] =  $param['price'];               //支付金额
//        $data['pay_time'] = date('Y-m-d H:i:s');     //支付时间
//        $data['add_time'] = time();                              //支付时间戳
//        $data['pay_fs'] = 0;                                     //支付方式
//        $data['openid'] = $param['openid'];                //会员openid
//        $data['sub_openid'] = $param['openid'];                //会员openid
//        $data['yf_price'] = $param['price'];        //应付金额
//        $data['zk_price'] = $data['price'] - $data['price'];     //折扣金额
//        $datalog['d_cashier'] = $param['nickname'];               //操作人
//        $Paylog = new Paylog();
//        $Paylog->allowField(true)->save($datalog);
//
//    }
//
//    /*
//     * code card_id openid price mid nickname orderid  con_username
//     * */
//    private function rec_cardupdate($param){
//        $datas['code'] = $param['code'];
//        $datas['card_id'] = $param['card_id'];
//        $datas['openid'] = $param['openid'];
//        $datas['record_balance'] = '消费';
//        $datas['pay_balance'] = $param['price'];
//        $datas['del_balance'] = $param['price'];
//        $datas['mid'] = $param['mid'];
//        $datas['con_username'] = $param['con_username'];
//        $datas['orderid'] = $param['orderid'];
//        $datas['hx_fs'] = 8;
//        $datas['type'] = 2;
//        $datas['cate'] = 2;
//        $datas['reason'] = 19;
//        $datas['source'] = 9;
//        $datas['create_time'] = time();
//        $CardUserUpdate = new CardUserUpdate();
//        $resut = $CardUserUpdate->allowField(true)->save($datas);
//        if ($resut) {
//            //carduserlog记录
//            $updataid = $CardUserUpdate->id;
//            $datas['up_id'] = $updataid;
//            $this->rec_cardlog($datas);
//        }
//    }
//
//    /*
//     * mid up_id openid orderid con_username  card_id  code  price
//     * */
//    public function rec_cardlog($param)
//    {
//        $CardUserLog = new CardUserLog();
//        $data['mid'] = $param['mid'];
//        $data['up_id'] = $param['up_id'];
//        $data['openid'] = $param['openid'];
//        $data['orderid'] = $param['orderid'];
//        $data['con_username'] = $param['con_username'];
//        $data['card_id'] = $param['card_id'];
//        $data['code'] = $param['code'];
//        //是否余额赠送
//        $data['num'] = $param['price'];
//        $data['type'] = 2;               //1充值/2核销
//        $data['cate'] = 2;               //1积分/2余额
//        $data['reason'] = 19;
//        $data['source'] = 9;
//        $data['create_time'] = time();
//        $CardUserLog->allowField(true)->save($data);
//    }
//
//    private function getorder($sh)
//    {
//        $order = "H" . $sh . "-" . date('YmdHis') . rand(10000, 99999) . rand(1, 9);
//        return $order;
//    }
//
//
//    //点击菜单送券
//    public function testclick(){
//        $CardPut = new CardPut();
//        $arr['gh_id'] = 'gh_7cce5f015893';
//        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
//        $arr['click_key'] = 'matter_free_44';
//        $res = $CardPut->clickmenuputcard($arr);
//        var_dump($res);
//
//    }
//
//
//    //查看自定义菜单设置
//    public function ckmuen(){
//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $opes = $this->options($card_id);
//        $wxObj = new Wxobjopen($opes);
//        $mul = $wxObj->getMenu();
//        var_dump($mul);
//    }
//
//    //
//    public function testapi(){
//        $arr['orderid'] = 'H501-20180526162414811966';
//        $arr['merchid'] = '501';
//        $res = action('api/httpPay/checkpay',$arr);
//        var_dump($res);
//    }
//
//    public function testcard(){
//        $arr['add_balance'] = '100';
//        $arr['id'] = '1851';
//        $arr['mid'] = '501';
//        $arr['record_balance'] = '后台核销';
//        $arr['type'] = '2';
//        $arr['username'] = "zhihuishangquan";
//        $res = $this->getcardupdate($arr);
//        return json($res);
//
//    }
//
//    public function testcardlist(){
//        $CardUserGet = new CardUserGet();
//        $map['card_id'] = 'pmbIgwY8FtPzSthi__yGA0Gi5WAs';
//        $list = $CardUserGet->where($map)->select();
//        $list['sume'] = count($list);
//        return json($list);
//    }
//
//    //获取会员卡详情
//    public function getcardinfowx($card_id){
//        $data=[
//            "card_id"=>$card_id
//        ];
//        $options = $this->options($card_id);
//        $wxObj = new Wxobjopen($options);
//        $res = $wxObj->getCardInfo($data);
//        return json($res);
//    }
//
//    //获取会员信息
//    public function getcardinfos(){
//        $arr = request()->param();
////        $CardUserGet = new CardUserGet();
////        $map['id'] = $arr['id'];
////        $user = $CardUserGet->where($map)->find();
//        $user['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $user['code'] = '819240230226';
//        $options = $this->options($user['card_id']);
//        var_dump(json_encode($options,JSON_UNESCAPED_UNICODE));
//        $WxObj = new Wxobjopen($options);
//        $data['code'] = $user['code'];
//        $data['card_id'] = $user['card_id'];
//        $res = $WxObj->userGetInfo($data);
////        $ss=file_get_contents('/data2/html/payos/44556677.txt');
////        echo $ss;
//        return json($res);
//    }
//
//    //余额更新微信操作  无通知
//    public function updatebalancenot(){
//        //实例化微信
//        $arr['code'] = 624738695186;
//        $arr['card_id'] = 'pUIDrwaDYgTiBa6Hts6W1aj2YnBk';
//        $arr['price'] = 209.64;
//        $options = $this->options($arr['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data = [
//            'code'=>$arr['code'],
//            'card_id'=>$arr['card_id'],
//            'custom_field_value2' => $arr['price'].'元',
//            'notify_optional'=>[
//                'is_notify_bonus'=>false,
//                'is_notify_balance'=>false,
//                'is_notify_custom_field2'=>false,
//            ],
//        ];
//        $res = $WxObj->updateUserInfo($data);
//        return json($res);
//    }

//余额更新微信操作  系统通知
//    public function updatebalance(){
//        $arr['card_id'] = 'pfMh91qqzu3iK4KY87A4LOfKacFE';
//        $arr['code'] = '240829327364';
//        $arr['price'] = '0.00';
//        //实例化微信
//        $options = $this->options($arr['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data = [
//            'code'=>$arr['code'],
//            'card_id'=>$arr['card_id'],
//            'custom_field_value2' => $arr['price'].'元',
//            'notify_optional'=>[
//                'is_notify_bonus'=>false,
//                'is_notify_balance'=>false,
//                'is_notify_custom_field2'=>false,
//            ],
//        ];
//        $res = $WxObj->updateUserInfo($data);
//        return json($res);
//    }
//
//    public function updatebonusnot(){
//        $CardUserGet = new CardUserGet();
//        $map['id'] = 286425;
//        $user = $CardUserGet->where($map)->find();
//        $options = $this->options($user['card_id']);
//        $WxObj = new Wxobjopen($options);
//        $data['code'] = $user['code'];
//        $data['card_id'] = $user['card_id'];
//        $data['bonus'] = 0;                     //积分全量   填300则不论之前有多少积分只剩300
//        $data['notify_optional']['is_notify_bonus'] = false;
//        $data['notify_optional']['is_notify_balance'] = false;
//        $data['notify_optional']['is_notify_custom_field1'] = false;
//        $res = $WxObj->updateUserInfo($data);
//        var_dump($res);
//    }
//
//    //
//    public function getlongicode(){
//        $map['code'] = 'BJb35QCsBjiX-3Z2h5FgaDDnBnWI80IeWk8oYicc5i-4bBpBX1';
//        $logincodes = new LoginCode();
//        $res = $logincodes->where($map)->find();
//        return json($res);
//    }
//
//    //领取会员详情
//    public function getCardInfo(){
//        if (Request()->isAjax()){
//            $arr = request()->post();
//            $CardUserGet = new CardUserGet();
//            $map['id'] = $arr['id'];
//            $user = $CardUserGet->where($map)->find();
//            return json($user);
//        }
//    }
//
//
//    public function testput(){
//        $teMsg = new TemplateMsg();
//        $arr['card_id'] = 'pJvpAxGb7dL0Z3T0dT34joDVx6oQ';
//        $arr['mid'] = '512';
//        $arr['rec_id'] = '1937';
//        $arr['openid'] = 'oJvpAxBksawUkVD6PpIFCIxDGs5w';
//        $arr['name'] = '蝶蝶蝶蝶变';
//        $arr['title'] = '充值送券';
//        $res = $teMsg->send_tpl('put_gift',$arr);
//        var_dump($res);
//    }
////
////    public function testpaylog(){
////        $map['orderid'] = 'H501-2018041215511723363';
//////        $map['orderno'] = '4200000093201804126976880077';
////        $PayLog = new Paylog();
////        $CardCzLog = new CardCzLog();
////
////        $res = $PayLog->where($map)->find();
////        $res['czlog'] = $CardCzLog->where($map)->find();
////        return json($res);
////    }
//
//    public function testcx(){
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $arr['type'] = '';
//        $res= action('api/api/api',[$arr]);
//        var_dump($res);
//    }
//
////    public function testgive(){
////        $arr['card_id'] = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
////        $arr['mid'] = '501';
////        $arr['top_mid'] = '1';
////        $arr['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
////        $arr['code'] = '819240230226';
////        $arr['nickname'] = '可参';
////        $arr['give_id'] = '56';
////        $arr['give_type'] = 'fire_card';
////
////        $cardput = new CardPut();
////        $res= $cardput->firecards($arr);
////        var_dump($res);
////    }
//
//    //
//    public function cardsis(){
//        $CardG = new CardGeneral();
//        $data['is_cgive'] = 1;
//        $res = $CardG->where(['is_cgive'=>0])->update($data);
//        var_dump($res);
//    }
//
//    //
//    public function testpaycard(){
//        $arr['orderid'] = 'H501-2018042610460112315';
//        $arr['get_card_id'] = '4457';
//        $arr['mid'] = '501';
//        $res = $this->pay_card_put($arr);
//        var_dump($res);
//    }
//
//    public function testpaycardjs(){
////        $arr['attach'] = 'ffcardbuy';
//        $arr['orderid'] = 'H501-2018042916565493963';
//        $res = $this->testpaycardus($arr);
//        var_dump($res);
//    }
//
//    //付费会员卡
//    public function testpaycardus($arr){
//        try {
//
//            $CardUserGet = new CardUserGet();
//            $CardPaycardlog = new CardPaycardlog();
//            $paycardus = $CardPaycardlog->where(['orderid'=>$arr['orderid']])->field('openid,user_code,putstatu')->find();
//            //等于1 则结束
//            if ($paycardus['putstatu'] == 1){
//                exit();
//            };
//            $user = $CardUserGet->where(['code' => $paycardus['user_code'],'openid'=>$paycardus['openid']])->field('code,card_id')->find();
//            $CardPaycardlog->allowField(true)->save(['paystatu'=>1],['orderid'=>$arr['orderid']]);
//            if ($user) {
//                $data['membership_number'] = $paycardus['user_code'];
//                $data['code'] = $paycardus['user_code'];
//                $data['card_id'] = $user['card_id'];
//                $CardMarke = new CardMarke();
//                $res = $CardMarke->activcardus($data);
//                if ($res['errcode'] == 0){
//                    $CardPaycardlog->allowField(true)->save(['putstatu'=>1],['orderid'=>$arr['orderid']]);
//                }
//            }else{
//                $res = '';
//            }
//            return $res;
//        }catch (\Exception $e){
//            $res = json_encode(array('code' => '9099', 'message' => $e->getMessage()));
//        }
//        return $res;
//    }
//
//
//    public function delpaycard(){
//        $data = [
//            'rule_id' => 421342294,
//        ];
//        $options = $this->optionss();
//        $weObj = new Wxobjopen($options);
//        $res = $weObj->payPutDel($data);
//        var_dump($res);
//    }
//
//
//    public function payinc(){
//        $arr['type'] = 'card_cz_que';
//        $arr['cate'] = 'bonus';
//        $arr['merchid'] = '501';
//        $arr['price'] = '1';
//        $arr['code'] = '819240230226';
//        $arr['user'] = 'qwe';
//        $res = action('api/api/api',[$arr]);
//        var_dump($res);
//    }
//
//    //微信API参数 根据mid获取
//    public function option($mid)
//    {
////        Session::set('openid', null);
//        $Agent = new Agent();
//        $WxOpen = new WxOpen();
//        $Merchant = new Merchant();
//        $map['id'] = $mid;
//        $merchantinfo= $Merchant->where($map)->field('wx_open_id,agent')->find();
//        $mab['id'] = $merchantinfo['wx_open_id'];
//        $config=$Agent->where(array('id'=>$merchantinfo['agent']))->find();
//        $users = $WxOpen->where($mab)->field('authorizer_appid,authorizer_refresh_token')->find();
//        $options = array(
//            'component_token' => $config['component_token'], // 填写你设定的key
//            'component_encodingaeskey' => $config['component_encodingaeskey'], // 填写加密用的EncodingAESKey
//            'component_appid' => $config['component_appid'], // 填写高级调用功能的app id
//            'component_appsecret' => $config['component_appsecret'], // 填写高级调用功能的密钥
//            'open_ticket' => $config['open_ticket'],
//            'authorizer_appid' => $users['authorizer_appid'],
//            'authorizer_refresh_token' => $users['authorizer_refresh_token'],
//        );
//        return $options;
//
//    }
//
//
    public function options($card_id)
    {

        //  Session::set('openid', null);
        $CardMember = new CardMember();
        $CardGeneral = new CardGeneral();
        $Merchant = new Merchant();
        $WxOpen = new WxOpen();
        $Agent=new Agent();
        $mid = $CardMember->where('card_id', $card_id)->value('mid');
        if ($mid) {
            $map['id'] = $mid;
        } else {
            $map['id'] = $CardGeneral->where(['card_id'=>$card_id])->value('mid');
        }
        $merchantinfo= $Merchant->where($map)->field('wx_open_id,agent')->find();
        $mab['id'] = $merchantinfo['wx_open_id'];
        $config=$Agent->where(array('id'=>$merchantinfo['agent']))->field('component_token,component_encodingaeskey,component_appid,component_appsecret,open_ticket')->find();
        $users = $WxOpen->where($mab)->field('authorizer_appid,authorizer_refresh_token')->find();
        $options = array(
            'component_token' => $config['component_token'], // 填写你设定的key
            'component_encodingaeskey' => $config['component_encodingaeskey'], // 填写加密用的EncodingAESKey
            'component_appid' => $config['component_appid'], // 填写高级调用功能的app id
            'component_appsecret' => $config['component_appsecret'], // 填写高级调用功能的密钥
            'open_ticket' => $config['open_ticket'],
            'authorizer_appid' => $users['authorizer_appid'],
            'authorizer_refresh_token' => $users['authorizer_refresh_token'],
        );
        return $options;
    }
//
//
//    //查询激活信息
//    public function getfireinfo(){
//        $data['card_id'] = 'pCVCLv7Bdh-bCiYNmkFIqfh4fwho';
//        $data['code'] = '256432469808';
//        $data['openid'] = 'oCVCLv2epPfR-zgO8v3HE7y5yjsw';
////        $data['createtime'] = '1524997335';
//        $data['orderid'] = 'H501-2018042919233352896';
////        var_dump($data);
////        exit();
//        $res = action('common/cardMarke/activcardus', array($data));
//        var_dump($res) ;
//    }
//
//    public function testlevel(){
//        $card_id = 'pCVCLvzUmdLGAf-zD_323DNrEQnY';
//        $user['code'] = '819240230226';
//        $user['bonus'] = '980';
//        $Level = new Level();
//        $res = $Level->checklevel($card_id,$user);
//        var_dump($res);
//    }

//付费购券
    /*
     *  orderid  get_card_id  mid
     * */
//    public function pay_card_put($updata)
//    {
////        return $updata;
//        $CardUserGet = new CardUserGet();
//        $CardPaycardlog = new CardPaycardlog();
//        $ComCardPut = new \app\common\controller\CardPut();
//        $paycardlost = $CardPaycardlog->where('orderid', $updata['orderid'])->field('id,putstatu')->find();
//        //如果等于1则结束
//        if ($paycardlost['putstatu'] == 1){
//            exit();
//        }
//        //查询领卡记录
//        $user = $CardUserGet->where('id', $updata['get_card_id'])->field('card_id,code,id,top_mid,openid,nickname')->find();
////        return $user;
//        //发放卡券
//        $arr['card_id'] = $user['card_id'];
//        $arr['code'] = $user['code'];
//        $arr['openid'] = $user['openid'];
//        $arr['nickname'] = $user['nickname'];
//        $arr['mid'] = $updata['mid'];
//        $arr['give_rec_id'] = $paycardlost['id'];
//        $arr['giveid'] = $CardPaycardlog->where('orderid', $updata['orderid'])->value('fid');
//        $arr['id'] = $user['id'];
//        $arr['top_mid'] = $user['top_mid'];
//
//        //余额更新
//        $arrc = $ComCardPut->payregsgive($arr);
////        $CardPaycardlog->allowField(true)->save(['putstatu'=>1],['orderid'=>$updata['orderid']]);
//        return $arrc;
//
//    }
//删除
//    public function testdel(){
//        $map['mid'] = ['in', $this->get_mer_mid()];
//        $Mstatis = new Mstatis();
//        $PayLog = new Paylog();
//        $CardCzgive = new CardCzgive();
//        $CardMember = new CardMember();
//        $CardGel = new CardGeneral();
//        $CardUserUpdate = new CardUserUpdate();
//        $CardUserGet = new CardUserGet();
//        $res['give'] = $CardCzgive->where($map)->delete();
//        $res['mstatis'] = $Mstatis->where($map)->delete();
//        $res['paylog'] = $PayLog->where($map)->delete();
//        $res['cardus'] = $CardMember->where($map)->delete();
//        $res['cards'] = $CardGel->where($map)->delete();
//        $res['cardup'] = $CardUserUpdate->where($map)->delete();
//        $res['cardget'] = $CardUserGet->where($map)->delete();
//        var_dump($res);

//    }

//orderid
//    public function testpay(){
//        $arr['merchid'] = '501';
//        $arr['price'] = '1';
////        $arr['user'] = 'ceshi2';
////        $arr['code'] = '548576770145';
////        $arr['cate'] = 'price';
////        $arr['csid'] = '';
////        $arr['price'] = 1;
//        $arr['auth_code'] = '135252862886259966';
//        $arr['cashier'] = 'ceshi2';
//        $arr['confirm'] = 'no';
//////        $arr['orderid'] = 'H501-20180402120609797001';
//        $arr['client_ip'] = '0.0.0.0';
//        $arr['type'] = 'pay';
//        $arr['fs'] = '';
////        $notify_url = Config::get('sysconfig.notify_url');
////        var_dump($notify_url);
//        $res= action('api/api/api',[$arr]);
//        var_dump($res);
//    }
//
//    public function getcardupdate()
//    {
//        if (Request()->isAjax()) {
//
//            $arr = request()->post();
////            return json($arr);
//            if ($arr['add_balance'] > 0) {
//                //数据库
//                $arr['nickname'] = '';
//                $arr['record_bonus'] = '后台核销';
//                $CardUserGet = new CardUserGet();
//                $CardMember = new CardMember();
//                $CardUserUpdate = new CardUserUpdate();
//                //查询
////                $map['id'] = $arr['id'];
//                $user = $CardUserGet->where(['id'=>$arr['id']])->field('bonus,cs_balance,balance,openid,code,card_id')->find();
//                $card = $CardMember->where('card_id', $user['card_id'])->field('card_id,card_type,is_cz_discount,is_cz_dj_discount,is_dedu_cards,discount')->find();
//                $conuser = Session::get('user');
//                //模版消息
//                $wxMesg = new Wxtemlpmesg();
//                $arr['record_bonus'] = '核销';
//                //判断余额
//                if ($arr['add_balance'] <= $user['balance']) {
//                    $ComBalance = new Balancet();
//                    //判断赠送金额是否为0   返回需扣除的余额
//                    $arrc = $ComBalance->checkbalance($arr,$user,$card);
//                    //更新余额
//                    $CardUserGet->where(['id'=>$arr['id']])->setDec('balance', $arrc['del_balance']);
//                    //交易记录
//                    //订单记录
//                    $arr['pay_balance'] = $arrc['del_balance'];     //实际支付额
//                    $arr['openid'] = $user['openid'];                //会员openid
//                    $arr['yf_price'] =  $arr['add_balance'];        //应付金额
//                    $arr['gel_card_zk'] = $arrc['gel_card_zk'];          //抵扣金额
//                    $arr['vip_card_zk'] = $arrc['vip_card_zk'];          //等级折扣金额
//                    $arr['dis_card_zk'] = $arrc['dis_card_zk'];          //会员折扣金额
//                    $arr['hx_card'] = $arrc['hx_card'];                   //抵扣卡券
//                    $datalog = $ComBalance->paylog_rec($arr);
//                    $arr['hx_fs'] = 8;
//                    $arr['type'] = 2;
//                    $arr['cate'] = 2;
//                    $arr['reason'] = 19;
//                    $arr['source'] = 1;
//                    $updataid = $ComBalance->cardupdate($arr,$user,$arrc);
//                    //核销卡券
//
//                    //发送模版消息
//                    $balance = $CardUserGet->where(['id'=>$arr['id']])->value('balance');
//                    $msg = ['add_balance' => $arrc['del_balance'], 'type' => 2, 'card_id' => $user['card_id'], 'openid' => $user['openid'], 'balance' => $balance];
//                    $wxMsg = new TemplateMsg();
//                    $res = $wxMsg->send_tpl('pay_balance',$msg);
//                    //保存发送记录
//                    $mesg['tplmesg_info'] = json_encode($res);
//                    $CardUserUpdate->save($mesg, ['id' => $updataid]);
//                    $bondata = ['code' => 0, 'message' => '核销成功！'];
//                } else {
//                    $bondata = ['code' => 9006, 'message' => '余额不足！'];
//                }
//            }else{
//                $bondata = ['code' => 9001, 'message' => '请输入正确的充值金额！'];
//            }
//            return json($bondata);
//        }
//
//    }
//




//微信API参数  根据card_id获取
//    public function options($card_id)
//    {
//        Session::set('openid', null);
//        $CardMember = new CardMember();
//        $Merchant = new Merchant();
//        $System = new System();
//        $WxOpen = new WxOpen();
//        $map['id'] = $CardMember->where('card_id', $card_id)->value('mid');
//        $mab['id'] = $Merchant->where($map)->value('wx_open_id');
//        $config = $System->where(array('id' => 1))->find();
//        $users = $WxOpen->where($mab)->find();
//        $options = array(
//            'component_token' => $config['component_token'], // 填写你设定的key
//            'component_encodingaeskey' => $config['component_encodingaeskey'], // 填写加密用的EncodingAESKey
//            'component_appid' => $config['component_appid'], // 填写高级调用功能的app id
//            'component_appsecret' => $config['component_appsecret'], // 填写高级调用功能的密钥
//            'open_ticket' => $config['open_ticket'],
//            'authorizer_appid' => $users['authorizer_appid'],
//            'authorizer_refresh_token' => $users['authorizer_refresh_token'],
//        );
//        return $options;
//    }

}
